October 2017
Intermediate to advanced
280 pages
6h 50m
English
Internally, Angular builds this hierarchy of injectors, but everything happens implicitly. In order to do this ourselves, we'll have to use lower level APIs which will be unusual for our day-to-day development process.
First, let's create an instance of an injector, in order to use it for the instantiation of registered tokens:
// ch6/manual-injector/instantiate.tsimport { Injector } from '@angular/core';// ...const injector = Injector.create([ { provide: BUFFER_SIZE, useValue: 42 }, { provide: Buffer, deps: [BUFFER_SIZE], useFactory: function (size: number) { return new Buffer(size); } }, { provide: Socket, deps: [Buffer], useFactory: function (buffer: Buffer) { return new Socket(buffer); } }]);
Here, first we import ...
Read now
Unlock full access