function
Allows to refer to references which are not yet defined.
forwardRef(forwardRefFn: ForwardRefFn): Type<any>
forwardRefFn | ForwardRefFn |
Type<any>
For instance, forwardRef
is used when the token
which we need to refer to for the purposes of DI is declared, but not yet defined. It is also used when the token
which we use when creating a query is not yet defined.
class Door { lock: Lock; // Door attempts to inject Lock, despite it not being defined yet. // forwardRef makes this possible. constructor(@Inject(forwardRef(() => Lock)) lock: Lock) { this.lock = lock; } } // Only at this point Lock is defined. class Lock {} const injector = Injector.create({providers: [{provide: Lock, deps: []}, {provide: Door, deps: [Lock]}]}); expect(injector.get(Door) instanceof Door).toBe(true); expect(injector.get(Door).lock instanceof Lock).toBe(true);
© 2010–2020 Google, Inc.
Licensed under the Creative Commons Attribution License 4.0.
https://v10.angular.io/api/core/forwardRef