First, the display injection device
Injector = Reflectiveinjector.resolveandcreate ([Car, Engine, Tires]); Let car = injector.get (car);
Second, a single case service
In the scope of an injector, the dependencies are singleton, because they share a service instance
Three, multi-example service
Angular di is a layered dependency injection system, which means that nested injectors can create their own service instances.
Iv. Role of @injectabled
Identifies a class that can be instantiated by an injector. Typically, when you attempt to instantiate a class that is not identified @Injectable()
, the injector will give an error.
It is recommended for each service class to @Injectable()
be added, including those that do not rely strictly and do not need it. Because:
Five, @Component, @Directive, @Pipe do not need to add adorners, because they are a subtype of @injectable.
ANGULAR2 Dependency Injection--the use of injectors