forwardRef

export forwardRef(forwardRefFn: ForwardRefFn) : Type

exported from angular2/core defined in angular2/src/core/di/forward_ref.ts (line 10)

Allows to refer to references which are not yet defined.

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.

Example

class Door { lock: Lock; constructor(@Inject(forwardRef(() => Lock)) lock: Lock) { this.lock = lock; } } // Only at this point Lock is defined. class Lock {} var injector = Injector.resolveAndCreate([Door, Lock]); var door = injector.get(Door); expect(door instanceof Door).toBe(true); expect(door.lock instanceof Lock).toBe(true);