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

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

EnvironmentInjector

Class
stable

An Injector that's part of the environment injector hierarchy, which exists outside of the component tree.

Types of injector hierarchies

On this page

    arrow_upward_alt Back to the top

    API

        
          abstract class EnvironmentInjector implements Injector {
    abstract get<T>(token: ProviderToken<T>, notFoundValue: undefined, options: InjectOptions & { optional?: false | undefined; }): T; abstract get<T>(token: ProviderToken<T>, notFoundValue: null | undefined, options: InjectOptions): T | null; abstract get<T>(token: ProviderToken<T>, notFoundValue?: T | undefined, options?: InjectOptions | undefined): T; abstract get<T>(token: string | ProviderToken<T>, notFoundValue?: any): any;
    abstract runInContext<ReturnT>(fn: () => ReturnT): ReturnT; abstract destroy(): void; abstract readonly destroyed: boolean;}

    get

    4 overloads

    Retrieves an instance from the injector based on the provided token.

    @paramtokenProviderToken<T>
    @paramnotFoundValueundefined
    @paramoptionsInjectOptions & { optional?: false | undefined; }
    @returnsT

    The instance from the injector if defined, otherwise the notFoundValue.

    Retrieves an instance from the injector based on the provided token.

    @paramtokenProviderToken<T>
    @paramnotFoundValuenull | undefined
    @paramoptionsInjectOptions
    @returnsT | null

    The instance from the injector if defined, otherwise the notFoundValue.

    Retrieves an instance from the injector based on the provided token.

    @paramtokenProviderToken<T>
    @paramnotFoundValueT | undefined
    @paramoptionsInjectOptions | undefined
    @returnsT

    The instance from the injector if defined, otherwise the notFoundValue.

    @deprecated

    from v4.0.0 use ProviderToken

    @paramtokenstring | ProviderToken<T>
    @paramnotFoundValueany
    @returnsany

    runInContext

    ReturnT

    Runs the given function in the context of this EnvironmentInjector.

    Within the function's stack frame, inject can be used to inject dependencies from this injector. Note that inject is only usable synchronously, and cannot be used in any asynchronous callbacks or after any await points.

    @deprecated

    use the standalone function runInInjectionContext instead

    @paramfn() => ReturnT

    the closure to be run in the context of this injector

    @returnsReturnT

    the return value of the function, if any

    destroy

    void
    @returnsvoid

    destroyed

    boolean

    Indicates whether the instance has already been destroyed.

    Jump to details

    Web Proxy Viewer  |  New URL  |  Original Page