fix(upgrade): throw error if trying to get injector before setting (#18209)
Previously, `undefined` would be returned. This change makes it easier to identify incorrect uses/bugs. (Discussed in https://github.com/angular/angular/pull/18213#issuecomment-316191308.)
This commit is contained in:

committed by
Miško Hevery

parent
4cd4f7a208
commit
d31dc7b2b3
@ -17,6 +17,10 @@ export function setTempInjectorRef(injector: angular.IInjectorService) {
|
||||
tempInjectorRef = injector;
|
||||
}
|
||||
export function injectorFactory() {
|
||||
if (!tempInjectorRef) {
|
||||
throw new Error('Trying to get the AngularJS injector before it being set.');
|
||||
}
|
||||
|
||||
const injector: angular.IInjectorService|null = tempInjectorRef;
|
||||
tempInjectorRef = null; // clear the value to prevent memory leaks
|
||||
return injector;
|
||||
|
Reference in New Issue
Block a user