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) {
|
||||
return this._compViewExpr.prop('ref');
|
||||
} 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 {
|
||||
var deps = this.meta.type.diDeps.map((diDep) => {
|
||||
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);
|
||||
});
|
||||
|
|
|
@ -591,17 +591,21 @@ export function main() {
|
|||
fakeAsync(() => {
|
||||
var cf = createCompFixture(
|
||||
'<div componentNeedsChangeDetectorRef></div>',
|
||||
tcb.overrideTemplate(PushComponentNeedsChangeDetectorRef,
|
||||
'{{counter}}<div directiveNeedsChangeDetectorRef></div>'));
|
||||
tcb.overrideTemplate(
|
||||
PushComponentNeedsChangeDetectorRef,
|
||||
'{{counter}}<div directiveNeedsChangeDetectorRef></div><div *ngIf="true" directiveNeedsChangeDetectorRef></div>'));
|
||||
cf.detectChanges();
|
||||
var compEl = cf.debugElement.children[0];
|
||||
var comp = compEl.inject(PushComponentNeedsChangeDetectorRef);
|
||||
var comp: PushComponentNeedsChangeDetectorRef =
|
||||
compEl.inject(PushComponentNeedsChangeDetectorRef);
|
||||
comp.counter = 1;
|
||||
cf.detectChanges();
|
||||
expect(compEl.nativeElement).toHaveText('0');
|
||||
compEl.children[0]
|
||||
.inject(DirectiveNeedsChangeDetectorRef)
|
||||
.changeDetectorRef.markForCheck();
|
||||
expect(compEl.children[0].inject(DirectiveNeedsChangeDetectorRef).changeDetectorRef)
|
||||
.toBe(comp.changeDetectorRef);
|
||||
expect(compEl.children[1].inject(DirectiveNeedsChangeDetectorRef).changeDetectorRef)
|
||||
.toBe(comp.changeDetectorRef);
|
||||
comp.changeDetectorRef.markForCheck();
|
||||
cf.detectChanges();
|
||||
expect(compEl.nativeElement).toHaveText('1');
|
||||
}));
|
||||
|
|
Loading…
Reference in New Issue