Sam
Sam

Reputation: 15770

Any difference between $injector and Inject() in AngularJS?

Is there any difference/preference between:

inject(function($injector) {
    rootScope = $injector.get('$rootScope');
});

And

inject(function($rootScope){
    rootScope = $rootScope;
});

Are the eqal as far as getting a resource injected into a test in Jasmine?

Upvotes: 1

Views: 515

Answers (1)

dnc253
dnc253

Reputation: 40337

From the documentation on the inject function:

The inject function wraps a function into an injectable function. The inject() creates new instance of $injector per test, which is then used for resolving references.

So, to answer your question, no, there really isn't a difference in the two ways, other than (in my opinion) it's a lot easier to just use the inject function to get dependencies instead of going through the $injector

Upvotes: 1

Related Questions