Cookies concent notice

This site uses cookies from Google to deliver its services and to analyze traffic.
Learn more
Skip to main content
Say hello to Angular's future home!Check out Angular.devHome
/

runInInjectionContext

Runs the given function in the context of the given Injector.

See more...

      
      runInInjectionContext<ReturnT>(injector: Injector, fn: () => ReturnT): ReturnT
    
Parameters
injector Injector

the injector which will satisfy calls to inject while fn is executing

fn () => ReturnT

the closure to be run in the context of injector

Returns

ReturnT: the return value of the function, if any

Description

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