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:
Georgios Kalpakas
2017-07-20 19:06:13 +03:00
committed by Miško Hevery
parent 4cd4f7a208
commit d31dc7b2b3
2 changed files with 10 additions and 2 deletions

View File

@ -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;