diff --git a/modules/angular2/src/compiler/view_compiler/compile_element.ts b/modules/angular2/src/compiler/view_compiler/compile_element.ts index 00035a97d1..0a554746de 100644 --- a/modules/angular2/src/compiler/view_compiler/compile_element.ts +++ b/modules/angular2/src/compiler/view_compiler/compile_element.ts @@ -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); } } } diff --git a/modules/angular2/src/compiler/view_compiler/compile_pipe.ts b/modules/angular2/src/compiler/view_compiler/compile_pipe.ts index 4c62c93133..8493aa3d55 100644 --- a/modules/angular2/src/compiler/view_compiler/compile_pipe.ts +++ b/modules/angular2/src/compiler/view_compiler/compile_pipe.ts @@ -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); }); diff --git a/modules/angular2/test/core/linker/view_injector_integration_spec.ts b/modules/angular2/test/core/linker/view_injector_integration_spec.ts index 2f91a1029c..e29ebe2625 100644 --- a/modules/angular2/test/core/linker/view_injector_integration_spec.ts +++ b/modules/angular2/test/core/linker/view_injector_integration_spec.ts @@ -591,17 +591,21 @@ export function main() { fakeAsync(() => { var cf = createCompFixture( '
', - tcb.overrideTemplate(PushComponentNeedsChangeDetectorRef, - '{{counter}}
')); + tcb.overrideTemplate( + PushComponentNeedsChangeDetectorRef, + '{{counter}}
')); 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'); }));