2

I've seen several questions about injecting lodash/underscore into controllers, but I need to put it into a custom provider. I can't seem to figure out how to do that. There is a similar question here that has an accepted answer, but I can't figure out how to re-purpose that technique for my situation.

I'm injecting lodash into angular as a separate module:

angular.module("lodash", [])
.factory("_", ($window) => {
    return $window._;
});

How would I modify or add to this in order to make lodash injectable into my provider?

1

1 Answer 1

4

To inject Lodash to both service providers and service instances use

angular.module("lodash", [])
.constant("_", window._);

instead . There are scenarios where using $window abstraction may be beneficial, but here it can be safely omitted.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.