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

TypeProvider

Configures the Injector to return an instance of Type when `Type' is used as the token.

查看"说明"...

interface TypeProvider extends Type{ // 继承自 core/Type constructor(...args: any[]): T }
      
      interface TypeProvider extends Type {

  // 继承自 core/Type
  constructor(...args: any[]): T
}
    

说明

Create an instance by invoking the new operator and supplying additional arguments. This form is a short form of TypeProvider;

For more details, see the "Dependency Injection Guide".

使用说明

@Injectable() class Greeting { salutation = 'Hello'; } const injector = ReflectiveInjector.resolveAndCreate([ Greeting, // Shorthand for { provide: Greeting, useClass: Greeting } ]); expect(injector.get(Greeting).salutation).toBe('Hello');
      
      @Injectable()
class Greeting {
  salutation = 'Hello';
}

const injector = ReflectiveInjector.resolveAndCreate([
  Greeting,  // Shorthand for { provide: Greeting, useClass: Greeting }
]);

expect(injector.get(Greeting).salutation).toBe('Hello');