fix(ivy): optional dependencies should not throw with module injector (#26763)
PR Close #26763
This commit is contained in:

committed by
Matias Niemelä

parent
1130e48541
commit
96770e5c6b
@ -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);
|
||||
|
@ -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) {
|
||||
|
Reference in New Issue
Block a user