填写这份《一分钟调查》,帮我们(开发组)做得更好!去填写Home

forwardRef

Allows to refer to references which are not yet defined.

查看"说明"...

forwardRef(forwardRefFn: ForwardRefFn): Type<any>
      
      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.

使用说明

Example

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 = ReflectiveInjector.resolveAndCreate([Door, Lock]); const door = injector.get(Door); expect(door instanceof Door).toBeTruthy(); expect(door.lock instanceof Lock).toBeTruthy();
      
      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 = ReflectiveInjector.resolveAndCreate([Door, Lock]);
const door = injector.get(Door);
expect(door instanceof Door).toBeTruthy();
expect(door.lock instanceof Lock).toBeTruthy();