Injector • Angular
Concrete injectors implement this interface. Injectors are configured with providers that associate dependencies of various types with injection tokens.
get
4 overloadsRetrieves an instance from the injector based on the provided token.
@paramnotFoundValueundefined
@returnsT
Retrieves an instance from the injector based on the provided token.
@paramnotFoundValuenull | undefined
@returnsT | null
Retrieves an instance from the injector based on the provided token.
@paramnotFoundValueT | undefined
@returnsT
@deprecated
from v4.0.0 use ProviderToken
@returnsany
THROW_IF_NOT_FOUND
{}create
2 overloads@deprecated
from v5 use the new signature Injector.create(options)
Creates a new injector instance that provides one or more dependencies,
according to a given type or types of StaticProvider.
Usage Notes
The following example creates a service injector instance.
class Square { name = 'square'; } const injector = Injector.create({providers: [{provide: Square, deps: []}]}); const shape: Square = injector.get(Square); expect(shape.name).toEqual('square'); expect(shape instanceof Square).toBe(true);