fix(core): return the ChangeDetectorRef of the component also for embedded views.

This commit is contained in:
Tobias Bosch 2016-04-29 12:58:45 -07:00
parent aecb60a604
commit 351f24e8eb
3 changed files with 12 additions and 8 deletions

View File

@ -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);
} }
} }
} }

View File

@ -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);
}); });

View File

@ -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');
})); }));