As a newcomer to Angular, I am exploring the use of $injector
and its get
function to retrieve specific services. For instance:
app.factory('$myService', function($injector) {
return { ...
var http = $injector.get('$http');
....
}
}
This code snippet shows how to assign the Angular $http
service to the variable http
.
In some other examples, I have encountered syntax like this:
app.factory('$myService', function($http) {
return {...}
Here, the $http
service is injected directly into the factory.
Are there any differences between these two approaches? When would be the appropriate time to use one over the other?
Thanks in advance!