Angular. JS learning dependency injection $ injector details, angular. jsinjector
Preface
Before dependency injection (IoC), it is very simple and straightforward to create an Object in the program, that is, to create a new Object in the code, we create, maintain, modify, and delete objects on our own. That is to say, we control the entire lifecycle of objects un
(7) understand the module and injector in angular, that is, dependency injection and angularinjector.
The benefits of dependency injection (DI) are no longer described in detail. Anyone who has used the spring framework knows the benefits. Angularjs, as a front-end js framework, also provides DI support, which is a feature not available in javascript/jquery. In angularjs, there are DI-related
(vii) Understand the module and injector in angular, that is, dependency injection time:2014-10-10 01:16:54 read:63060 Comments:1 Favorites:0 [Point I collection +] Tags: angular injector angular Dependency InjectionThe benefits of Dependency injection (DI) are no longer m
The benefits of dependency injection (DI) are no longer described in detail. Anyone who has used the Spring framework knows the benefits. Angularjs, as a front-end JS framework, also provides di support, which is a feature not available in Javascript/jquery. In angularjs, there are di-related angular. Module (), angular. injector (), $
The benefits of Dependency injection (DI) are no longer to be mentioned, as is known with the spring Framework. Angularjs as the foreground JS frame. Support for Di is also provided. This is a feature that Javascript/jquery does not have.The Angularjs is related to di with Angular.module (), angular.injector (), NBSP; $injector, $provide object can be Applicationcontext.getbean () implemented; a dependency declaration, which can be configured in a
Angular. JS learning-dependency injection $ injector
Before dependency injection (IoC), it is very simple and straightforward to create an Object in the program, that is, to create a new Object in the code, we create, maintain, modify, and delete objects on our own. That is to say, we control the entire lifecycle of objects until they are not referenced and recycled. It is true that this practice is unders
The benefits of Dependency injection (DI) are no longer mentioned, as is known with the spring Framework. Angularjs as the foreground JS framework, also provides the support for Di, this is javascript/jquery not have the characteristic. In Angularjs, Angular.module (), Angular.injector (), $injector, $provide are associated with Di. For a DI container, you must have 3 elements: the registration of the service, the Declaration of the dependency, and th
The benefits of Dependency injection (DI) are no longer mentioned, as is known with the spring Framework. Angularjs as the foreground JS framework, also provides the support for Di, this is javascript/jquery not have the characteristic. In Angularjs, Angular.module (), Angular.injector (), $injector, $provide are associated with Di. For a DI container, you must have 3 elements: the registration of the service, the Declaration of the dependency, and th
AngularJS dependency injection instance analysis (using module and injector), angularjsinjector
This article analyzes the dependency injection of AngularJS. We will share this with you for your reference. The details are as follows:
The benefits of dependency injection (DI) are no longer described in detail. Anyone who has used the spring framework knows the benefits. AngularJS, as a front-end js framework, also provides DI support, which is a feature
. More accurately, $ rootScope is created by the core module ng of angularJS.
Example 1:
// Create a module var module = angular. module ("app", []); // true indicates that $ rootScope is indeed included in the module's injector as a service. var hasNgInjector = angular. injector (['app', 'ng ']); console. log ("has
("App", []);//True to indicate that $rootscope is indeed included in the module's injector in the form of a service var hasnginjector = Angular.injector ([' app ', ' ng ']); Console.log ("Has $rootScope =" + Hasnginjector.has ("$rootScope"))//true//gets the corresponding injector object of the module, does not acquire the services in the NG module//Does not depend on the NG module, Unable to get $rootscop
Read Catalogue
Inferred injection
Tagged injection
Inline-Injection
$injector Common methods
Sample code
There are also concepts of dependency injection in Angularjs, like dependency injection in spring, but different. There are some additional things you need to do to use construct injection or set value injection in spring, but it is convenient to just declare it where you need it, like a reference to a module
and Instanceinjector ( The differences between the two objects are mainly the different cache objects passed by the Createinternalinjector method, and the Instanceinjector is derived by Angular.injector (). For Providerinjector, it is primarily used to obtain service providers, i.e. serviceprovider. For Instanceinjector, the main purpose is to perform the methods of provider objects obtained from Providerinjector $get , produce service objects (dependencies), and pass the service objects to the
official documentation.For ease of commissioning, we added @host ().@HostThe adorner will cut the behavior of the search to the host componentDETAIL.TS Hint Detail component add @host () adorner1Import {Component, host}from ' @angular/core ';2Import {loggerservice}from './logger.service ';3 @Component ({4Selector: ' Detail ',5 ModuleId:module.id,6Templateurl: './app-detail.component.html ',7 providers: [8 //{provide:loggerservice, useclass:logg
......, All of this can be done through the service.
The task of components is to provide user experience. That's all!
It is between a view (rendered by a template) and an application logic (including a model.
Well-designed components provide attributes and methods for data binding and delegate unimportant tasks to the service.
Dependency Injection
Dependency injection is a method for providing new instances of classes and is responsible for handling all dependencies (services) required by clas
parameters (as with tag injection).
App.controller ("MyCtrl3", [' $scope ', ' hello1 ', ' Hello2 ', function ($scope, Hello1,hello2) {
$scope. Hello = function () {
Hello1.hello ();
Hello2.hello ();
}
]);
$injector Common methods
In angular, the injector can be obtained by Angular.injector ().
var $
Several injection methods in a angularjs the use of construct injection or set value injection in spring requires some additional action, but it is very convenient to simply declare it in the angular where it is needed, like a reference to a module. There are several injection methods in ANGULARJS: Inferred injection: This injection method requires the same parameter name as the service name. If the code is compressed and so on, it will cause the inje
Angularjs source code parsing: injector and angularjsinjector
Introduction
Injector is used for Automatic Parameter injection, for example
function fn ($http, $scope, aService) {}
Ng automatically transmits $ http, $ scope, and aService as parameters for execution at runtime.
In fact, it is easy to understand that injector has done two things.
Cache those serv
parameters. In JS, we can introduce the dependency
Using global variable references
Pass through function arguments where needed
The disadvantage of using global variables is that it pollutes the global namespace, and the reference is passed through a function, and can be implemented in two ways:
Closure delivery
The background resolves the dependent objects and passes the arguments through the Function.prototype.call
In Angularjs, dependency injection is
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.