fix(ivy): optional dependencies should not throw with module injector (#26763)

PR Close #26763
This commit is contained in:
Kara Erickson
2018-10-25 11:35:51 -07:00
committed by Matias Niemelä
parent 1130e48541
commit 96770e5c6b
4 changed files with 94 additions and 44 deletions

View File

@ -178,8 +178,8 @@ export class R3Injector {
// Select the next injector based on the Self flag - if self is set, the next injector is
// the NullInjector, otherwise it's the parent.
let next = !(flags & InjectFlags.Self) ? this.parent : getNullInjector();
return this.parent.get(token, notFoundValue);
const nextInjector = !(flags & InjectFlags.Self) ? this.parent : getNullInjector();
return nextInjector.get(token, notFoundValue);
} finally {
// Lastly, clean up the state by restoring the previous injector.
setCurrentInjector(previousInjector);

View File

@ -368,6 +368,11 @@ export function getOrCreateInjectable<T>(
}
}
if (flags & InjectFlags.Optional && notFoundValue === undefined) {
// This must be set or the NullInjector will throw for optional deps
notFoundValue = null;
}
if ((flags & (InjectFlags.Self | InjectFlags.Host)) === 0) {
const moduleInjector = lViewData[INJECTOR];
if (moduleInjector) {