Interviews4 answers
What is use of @Injector in Angular
4 Answers
injector is used to retrieve object instances as defined by provider, instantiate types, invoke methods, and load modules.
Asad IlyasPosted Apr 12, 2018, 8:09 AM EDT
injector is used to retrieve object instances as defined by provider, instantiate types, invoke methods, and load modules.
Asad IlyasPosted Apr 12, 2018, 8:09 AM EDT
injector is used to retrieve object instances as defined by provider, instantiate types, invoke methods, and load modules.
Asad IlyasPosted Apr 12, 2018, 8:09 AM EDT
A service can be dynamically injected (by name) into a controller using the $injector. Being able to inject services via controller arguments is just a convenience that Angular provides. Under the hood, the $injector is used by Angular to retrieve object instances. But we can use the $injector ourselves also.
function MyCtrl($scope, $injector) {
$scope.doSomething = function(someService) {
var service = $injector.get(someService) // someService contains the name of a service
service.value += 10
}
https://stackoverflow.com/questions/14415845/angularjs-dynamically-inject-scope-or-controller/14418384#14418384
https://docs.angularjs.org/api/auto/service/$injector
Jaipal ReddyPosted Apr 3, 2018, 4:50 AM EDT


