[ Web Proxy ]
URL:
Viewing: https://angular.dev/api/core/TypeProvider [Back]  [Original]

TypeProvider Angular Skip to main content
menu
close
more_horiz
menuAPI
@angular/core

TypeProvider

interface
stable

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

On this page

    arrow_upward_alt Back to the top

    API

        
          interface TypeProvider extends Type<any> {  override apply(this: Function, thisArg: any, argArray?: any): any;  override call(this: Function, thisArg: any, ...argArray: any[]): any;  override bind(this: Function, thisArg: any, ...argArray: any[]): any;  override toString(): string;  readonly override length: number;  override arguments: any;  override caller: Function;  readonly override name: string;  override [Symbol.hasInstance](value: any): boolean;}
        
        

    apply

    any

    Calls the function, substituting the specified object for the this value of the function, and the specified array for the arguments of the function.

    @paramthisFunction
    @paramthisArgany

    The object to be used as the this object.

    @paramargArrayany

    A set of arguments to be passed to the function.

    @returnsany

    call

    any

    Calls a method of an object, substituting another object for the current object.

    @paramthisFunction
    @paramthisArgany

    The object to be used as the current object.

    @paramargArrayany[]

    A list of arguments to be passed to the method.

    @returnsany

    bind

    any

    For a given function, creates a bound function that has the same body as the original function. The this object of the bound function is associated with the specified object, and has the specified initial parameters.

    @paramthisFunction
    @paramthisArgany

    An object to which the this keyword can refer inside the new function.

    @paramargArrayany[]

    A list of arguments to be passed to the new function.

    @returnsany

    toString

    string

    Returns a string representation of a function.

    @returnsstring

    length

    number

    caller

    Function

    name

    string

    Returns the name of the function. Function names are read-only and can not be changed.

    [Symbol.hasInstance]

    boolean

    Determines whether the given value inherits from this function if this function was used as a constructor function.

    A constructor function can control which objects are recognized as its instances by 'instanceof' by overriding this method.

    @paramvalueany
    @returnsboolean

    Description

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

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

    Usage Notes

    @Injectable()
            class Greeting {
              salutation = 'Hello';
            }
    
            const injector = Injector.create({providers: [{provide: Greeting, useClass: Greeting}]});
    
            expect(injector.get(Greeting).salutation).toBe('Hello');
    Jump to details

    Web Proxy Viewer  |  New URL  |  Original Page