W3cubDocs

/Angular

runInInjectionContext

function

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.

© 2010–2023 Google, Inc.
Licensed under the Creative Commons Attribution License 4.0.
https://angular.io/api/core/runInInjectionContext