Angular · Senior · Question 17 of 75

What is runInInjectionContext for?

runInInjectionContext(this.injector, () => {
  const data = toSignal(inject(Api).load(id));
});

Explanation

Inject Injector during construction, then use it later in a method or callback. Many APIs (toSignal, effect, takeUntilDestroyed) alternatively accept an injector option.

Further reading

Problem with a question

Angular · Senior · question 17

Test yourself

Take the Angular · Senior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz