Skip to content

docs(zones): show how to keep AngularFire calls in an injection context#3721

Open
armando-navarro wants to merge 1 commit into
angular:mainfrom
armando-navarro:docs-zones-injection-context
Open

docs(zones): show how to keep AngularFire calls in an injection context#3721
armando-navarro wants to merge 1 commit into
angular:mainfrom
armando-navarro:docs-zones-injection-context

Conversation

@armando-navarro

Copy link
Copy Markdown
Collaborator

The zone-wrappers guide explains what the "outside of an Injection context" warning means and how to change its log level, but never shows how to fix the code that triggers it. #3629 asks for exactly that.

This adds a "Keeping calls inside an injection context" section covering the most common trigger: an AngularFire API called inside an async callback (for example a Firestore query built inside a switchMap on the signed-in user), where the callback runs after the synchronous injection context is gone. The recipe captures an EnvironmentInjector while the context is active and re-establishes it inside the callback with runInInjectionContext, plus a note to prefer hoisting the call out of the callback when it doesn't depend on the async value.

Docs-only; no code or behavior change.

Fixes #3629

The zone-wrappers guide explains what the "outside of an Injection context" warning means and how to change its log level, but never shows how to fix the code that triggers it. angular#3629 asks for exactly that.

This adds a "Keeping calls inside an injection context" section covering the most common trigger: an AngularFire API called inside an async callback (for example a Firestore query built inside a switchMap on the signed-in user), where the callback runs after the synchronous injection context is gone. The recipe captures an EnvironmentInjector while the context is active and re-establishes it inside the callback with runInInjectionContext, plus a note to prefer hoisting the call out of the callback when it doesn't depend on the async value.

Docs-only; no code or behavior change.

Fixes angular#3629

@tyler-reitz tyler-reitz left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good addition. The two-example structure works well: hoist when you can, runInInjectionContext when you need the per-emission value. The EnvironmentInjector field pattern is the right way to bridge the sync/async boundary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Firebase API called outside injection context - missing details on how to fix this

2 participants