fix(core): return the ChangeDetectorRef of the component also for embedded views.
This commit is contained in:
parent
aecb60a604
commit
351f24e8eb
|
@ -306,7 +306,7 @@ export class CompileElement extends CompileNode {
|
||||||
if (requestingProviderType === ProviderAstType.Component) {
|
if (requestingProviderType === ProviderAstType.Component) {
|
||||||
return this._compViewExpr.prop('ref');
|
return this._compViewExpr.prop('ref');
|
||||||
} else {
|
} else {
|
||||||
return o.THIS_EXPR.prop('ref');
|
return getPropertyInView(o.THIS_EXPR.prop('ref'), this.view, this.view.componentView);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,7 @@ export class CompilePipe {
|
||||||
create(): void {
|
create(): void {
|
||||||
var deps = this.meta.type.diDeps.map((diDep) => {
|
var deps = this.meta.type.diDeps.map((diDep) => {
|
||||||
if (diDep.token.equalsTo(identifierToken(Identifiers.ChangeDetectorRef))) {
|
if (diDep.token.equalsTo(identifierToken(Identifiers.ChangeDetectorRef))) {
|
||||||
return o.THIS_EXPR.prop('ref');
|
return getPropertyInView(o.THIS_EXPR.prop('ref'), this.view, this.view.componentView);
|
||||||
}
|
}
|
||||||
return injectFromViewParentInjector(diDep.token, false);
|
return injectFromViewParentInjector(diDep.token, false);
|
||||||
});
|
});
|
||||||
|
|
|
@ -591,17 +591,21 @@ export function main() {
|
||||||
fakeAsync(() => {
|
fakeAsync(() => {
|
||||||
var cf = createCompFixture(
|
var cf = createCompFixture(
|
||||||
'<div componentNeedsChangeDetectorRef></div>',
|
'<div componentNeedsChangeDetectorRef></div>',
|
||||||
tcb.overrideTemplate(PushComponentNeedsChangeDetectorRef,
|
tcb.overrideTemplate(
|
||||||
'{{counter}}<div directiveNeedsChangeDetectorRef></div>'));
|
PushComponentNeedsChangeDetectorRef,
|
||||||
|
'{{counter}}<div directiveNeedsChangeDetectorRef></div><div *ngIf="true" directiveNeedsChangeDetectorRef></div>'));
|
||||||
cf.detectChanges();
|
cf.detectChanges();
|
||||||
var compEl = cf.debugElement.children[0];
|
var compEl = cf.debugElement.children[0];
|
||||||
var comp = compEl.inject(PushComponentNeedsChangeDetectorRef);
|
var comp: PushComponentNeedsChangeDetectorRef =
|
||||||
|
compEl.inject(PushComponentNeedsChangeDetectorRef);
|
||||||
comp.counter = 1;
|
comp.counter = 1;
|
||||||
cf.detectChanges();
|
cf.detectChanges();
|
||||||
expect(compEl.nativeElement).toHaveText('0');
|
expect(compEl.nativeElement).toHaveText('0');
|
||||||
compEl.children[0]
|
expect(compEl.children[0].inject(DirectiveNeedsChangeDetectorRef).changeDetectorRef)
|
||||||
.inject(DirectiveNeedsChangeDetectorRef)
|
.toBe(comp.changeDetectorRef);
|
||||||
.changeDetectorRef.markForCheck();
|
expect(compEl.children[1].inject(DirectiveNeedsChangeDetectorRef).changeDetectorRef)
|
||||||
|
.toBe(comp.changeDetectorRef);
|
||||||
|
comp.changeDetectorRef.markForCheck();
|
||||||
cf.detectChanges();
|
cf.detectChanges();
|
||||||
expect(compEl.nativeElement).toHaveText('1');
|
expect(compEl.nativeElement).toHaveText('1');
|
||||||
}));
|
}));
|
||||||
|
|
Loading…
Reference in New Issue