Cookies concent notice

This site uses cookies from Google to deliver its services and to analyze traffic.
Learn more
Skip to main content
This site is no longer updated.Head to Angular.devHome
/

This is the archived documentation for Angular v17. Please visit angular.dev to see this page for the current version of Angular.

TypeProvider

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

See more...

      
      interface TypeProvider extends Type<any> {

  // inherited from core/Type
  constructor(...args: any[]): T
}
    

Description

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".

Further information is available in the Usage Notes...

Usage notes

      
      @Injectable()
class Greeting {
  salutation = 'Hello';
}

const injector = Injector.create({providers: [{provide: Greeting, useClass: Greeting}]});

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