Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can it be injected into another provider? #70

Closed
yleemj opened this issue Nov 12, 2014 · 5 comments
Closed

Can it be injected into another provider? #70

yleemj opened this issue Nov 12, 2014 · 5 comments

Comments

@yleemj
Copy link

yleemj commented Nov 12, 2014

app.provider('Item', ['$localStorage',
function($localStorage) {
................
}])

seems not working, cannot find the $localStorage provider

@GabrielGil
Copy link

Just inject it in your app and on the closure.

app.module('yourMod', ['ngStorage']);
app.provider('item', function($localStorage) {});

@egilkh
Copy link
Contributor

egilkh commented May 13, 2015

Can also be done with more explicit dependency injection

app.module('yourMod', ['ngStorage']);
app.provider('item', ['$localStorage', function($localStorage) {}]);

@egilkh egilkh closed this as completed May 13, 2015
@GabrielGil
Copy link

Just curiosity, what is the main advantage/difference of injecting it the way you proposed with an array @egilkh?

@egilkh
Copy link
Contributor

egilkh commented May 13, 2015

Mainly I think it's useful for minify/uglify tasks that try to mangle your parameters. Another thing you can do is "alias" the name of the injection. Example:

app.provider('item', ['$localStorage', function(ls) {}]);

Personally I like it more because it's just more verbose and there is no guesswork when reading the code.

For reference: https://docs.angularjs.org/guide/di

@GabrielGil
Copy link

Makes lot of sense. Thank you for the note and the reference. So useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants