Angularjs All functional components are organized in the form of dependency injection, and all components must be decoupled by means of containers (injectors) to access each other;
1. The injector stores all recipes (name + class constructors): When Angualrjs starts, the component (Provider) is first registered by name in the injector;
2, the component requires a $get function (class factory), injector by calling the function to obtain an instance of the component
<HTML><Head> <title>modifying data</title> <MetaCharSet= ' Utf-8 '> <Scripttype= "Text/javascript"src= '.. \bower_components\angularjs\angular.min.js '> </Script> <Scripttype= "Text/javascript">Angular.module ("Stater", []). Provider ("Echello",function(){ //provide a class factory This. $get= function(){ return "Hello Word"; }}) angular.element (document). Ready (function(){ //Create an injector, call the class factory function, get the instance //invoke () invokes a function body directly, and injects the dependent service object through the function parameter name injection or the dependency array injection; //1. Injection of parameter namesAngular.injector (["ng","Stater"]). Invoke (function(Echello) {vare=Document.queryselector ("#logger"); Angular.element (E). Text (Echello)})//2. Dependent array injection, this time no matter what parameters are filled, the results will not be affectedAngular.injector (["ng","Stater"]). Invoke (["Echello",function(v) {vare=Document.queryselector ("#logger"); Angular.element (E). Text (v)}])})</Script><BodyNg-app= "Stater"> <!--ANGULARJS All functional components are organized in the form of dependency injection, and all components must be decoupled by means of containers (injectors) to access each other; 1. The injector stores all recipes (name + class constructors): When Angualrjs starts, the component (Provider) is first registered by name in the injector; 2, the component requires a $get function (class factory), injector by calling the function to obtain an instance of the component - <DivID= "Logger"></Div></Body></HTML>
angularjs--Dependency Injection