angularjs--Dependency Injection

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.