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.

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.