fix(ivy): ngUpgrade should distinguish element and module injectors (#28313)
There are cases where we should check an element injector but don't go into the associated module injector if a token is not found. In both the view engine and ngIvy this is acheived by passing the `NOT_FOUND_CHECK_ONLY_ELEMENT_INJECTOR` as the `notFoundValue`. Before this fix the view engine and ngIvy were using different objects to represent `NOT_FOUND_CHECK_ONLY_ELEMENT_INJECTOR`. This was causing problems as ngUpgrade is using `NOT_FOUND_CHECK_ONLY_ELEMENT_INJECTOR` const in its `NgAdapterInjector` to prevent searching of module injectors. This commit makes sure that ngIvy is using the same object to represent `NOT_FOUND_CHECK_ONLY_ELEMENT_INJECTOR` as the view engine. PR Close #28313
This commit is contained in:
parent
22a43cff4d
commit
32c61f434c
|
@ -19,6 +19,7 @@ import {RendererFactory2} from '../render/api';
|
|||
import {Sanitizer} from '../sanitization/security';
|
||||
import {assertDefined} from '../util/assert';
|
||||
import {VERSION} from '../version';
|
||||
import {NOT_FOUND_CHECK_ONLY_ELEMENT_INJECTOR} from '../view/provider';
|
||||
|
||||
import {assertComponentType} from './assert';
|
||||
import {LifecycleHooksFeature, createRootComponent, createRootComponentView, createRootContext} from './component';
|
||||
|
@ -74,8 +75,6 @@ export const SCHEDULER = new InjectionToken<((fn: () => void) => void)>('SCHEDUL
|
|||
factory: () => defaultScheduler,
|
||||
});
|
||||
|
||||
const NOT_FOUND_CHECK_ONLY_ELEMENT_INJECTOR = {};
|
||||
|
||||
function createChainedInjector(rootViewInjector: Injector, moduleInjector: Injector): Injector {
|
||||
return {
|
||||
get: <T>(token: Type<T>| InjectionToken<T>, notFoundValue?: T): T => {
|
||||
|
|
|
@ -736,9 +736,7 @@ withEachNg1Version(() => {
|
|||
});
|
||||
}));
|
||||
|
||||
fixmeIvy(
|
||||
'FW-717: Injector on lazy loaded components are not the same as their NgModule\'s injector')
|
||||
.it('should work with ng2 lazy loaded components', async(() => {
|
||||
it('should work with ng2 lazy loaded components', async(() => {
|
||||
let componentInjector: Injector;
|
||||
|
||||
@Component({selector: 'ng2', template: ''})
|
||||
|
@ -778,8 +776,8 @@ withEachNg1Version(() => {
|
|||
const compiler = modInjector.get(Compiler);
|
||||
const modFactory = compiler.compileModuleSync(LazyLoadedModule);
|
||||
const childMod = modFactory.create(modInjector);
|
||||
const cmpFactory = childMod.componentFactoryResolver.resolveComponentFactory(
|
||||
LazyLoadedComponent) !;
|
||||
const cmpFactory =
|
||||
childMod.componentFactoryResolver.resolveComponentFactory(LazyLoadedComponent) !;
|
||||
const lazyCmp = cmpFactory.create(componentInjector);
|
||||
|
||||
expect(lazyCmp.instance.module.injector === childMod.injector).toBe(true);
|
||||
|
|
|
@ -416,8 +416,7 @@ withEachNg1Version(() => {
|
|||
});
|
||||
}));
|
||||
|
||||
fixmeIvy('FW-873: projected component injector hierarchy not wired up correctly')
|
||||
.it('should correctly traverse the injector tree of downgraded components (from different modules)',
|
||||
it('should correctly traverse the injector tree of downgraded components (from different modules)',
|
||||
async(() => {
|
||||
@Component({
|
||||
selector: 'ng2A',
|
||||
|
@ -532,8 +531,7 @@ withEachNg1Version(() => {
|
|||
// Standalone component B.
|
||||
$rootScope.$apply('showB2 = true');
|
||||
expect(multiTrim(element.children[1].textContent))
|
||||
.toBe(
|
||||
'FOO:CompB-foo BAR:ModB-bar BAZ:ModB-baz QUX:Plat-qux QUUX:Plat-quux');
|
||||
.toBe('FOO:CompB-foo BAR:ModB-bar BAZ:ModB-baz QUX:Plat-qux QUUX:Plat-quux');
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
|
Loading…
Reference in New Issue