In fact, angular injection service is quite complex, at present, see the source code also only understand half, in order not to mislead everyone, I do not dare to speak too complex, afraid of their own understanding is wrong.
First of all we need to know three ways to inject angular:
The first type: Inference
var function ($scope) { }
The second type: annotation
var function ($location) { console.log (' Module: Code injection $location Success '); Console.log ($location); = [' $location ']; $injector. Invoke (MyModule);
The third type: inline
var MyTest = [' $location ',function($location) {}]
varMyTest = [' $location ',function($location) {Console.log (' Test: Code injection $location Success '); Console.log ($location); }] varMyModule =function($location) {Console.log (' Module: Code injection $location Success '); Console.log ($location); } angular.module (' MyApp ', []). Run (function($injector) {console.log ($injector); //functionality is the same as injection-time declarations, but when injected, it is sometimes possible to inject a solution within a function by declaring a recurring dependency problem. Console.log ($injector. Get (' $http ')); //Dependency Injection used to get an objectConsole.log ($injector. Annotate (MyTest)); //injection function, when you define a function, beyond the specifications of NG, you can choose to inject the function in this way to achieve the purpose of accessing NG built-in services$injector. Invoke (MyTest); //whether the current service existsConsole.log ($injector. has (' Myfact ')); //mymodule. $inject = [' $location '] //$injector. Invoke (MyModule);}). Factory (' Myfact ',function(){ return{}}). controller (' Myctrl ',function(){ })
Introducing Angular Injection Services