mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
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:
committed by
Andrew Scott
parent
f87aa2da8c
commit
6b52f03f5f
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user