From 6b52f03f5fc6e8c1efa757847b32ae4ce2e595ac Mon Sep 17 00:00:00 2001 From: Pawel Kozlowski Date: Fri, 27 May 2022 13:13:56 +0200 Subject: [PATCH] fix(core): add more details to the MISSING_INJECTION_CONTEXT error (#46166) The MISSING_INJECTION_CONTEXT runtime error can be thrown when the inject function is used outside of the class creation context. Before this change we've only used a vague terms of the 'injection context'. This commit extends the error message to indicate that we really talk about the class construction context. PR Close #46166 --- packages/core/src/di/injector_compatibility.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/core/src/di/injector_compatibility.ts b/packages/core/src/di/injector_compatibility.ts index e1e054dd145..2bd1d32c606 100644 --- a/packages/core/src/di/injector_compatibility.ts +++ b/packages/core/src/di/injector_compatibility.ts @@ -55,7 +55,7 @@ export function injectInjectorOnly(token: ProviderToken, flags = InjectFla null { if (_currentInjector === undefined) { const errorMessage = (typeof ngDevMode === 'undefined' || ngDevMode) ? - `inject() must be called from an injection context` : + `inject() must be called from an injection context (a constructor, a factory function or a field initializer)` : ''; throw new RuntimeError(RuntimeErrorCode.MISSING_INJECTION_CONTEXT, errorMessage); } else if (_currentInjector === null) {