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
This commit is contained in:
Pawel Kozlowski
2022-05-27 10:15:56 -07:00
committed by Andrew Scott
parent 12938577ef
commit 35653ce337
@@ -55,7 +55,7 @@ export function injectInjectorOnly<T>(token: ProviderToken<T>, 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) {