From 5753de50f04659fac6d76e2777cffa52c2afe013 Mon Sep 17 00:00:00 2001 From: Victor Berchet Date: Wed, 1 Mar 2017 08:03:14 -0800 Subject: [PATCH] fix(core): fix `isComponentView()` and `isEmbeddedView()` tests (#14789) fixes #14778 --- .../common/test/directives/ng_template_outlet_spec.ts | 9 +++++++++ modules/@angular/core/src/view/util.ts | 4 ++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/modules/@angular/common/test/directives/ng_template_outlet_spec.ts b/modules/@angular/common/test/directives/ng_template_outlet_spec.ts index fb3cffd141..3c9c060a03 100644 --- a/modules/@angular/common/test/directives/ng_template_outlet_spec.ts +++ b/modules/@angular/common/test/directives/ng_template_outlet_spec.ts @@ -34,6 +34,15 @@ export function main() { }); }); + // https://github.com/angular/angular/issues/14778 + it('should accept the component as the context', async(() => { + const template = `` + + `{{context.foo}}`; + + fixture = createTestComponent(template); + detectChangesAndExpectText('bar'); + })); + it('should do nothing if templateRef is `null`', async(() => { const template = ``; fixture = createTestComponent(template); diff --git a/modules/@angular/core/src/view/util.ts b/modules/@angular/core/src/view/util.ts index 8984587694..9111896ade 100644 --- a/modules/@angular/core/src/view/util.ts +++ b/modules/@angular/core/src/view/util.ts @@ -141,11 +141,11 @@ export function elementEventFullName(target: string, name: string): string { } export function isComponentView(view: ViewData): boolean { - return view.component === view.context && !!view.parent; + return !!view.parent && !!(view.parentNodeDef.flags & NodeFlags.Component); } export function isEmbeddedView(view: ViewData): boolean { - return view.component !== view.context && !!view.parent; + return !!view.parent && !(view.parentNodeDef.flags & NodeFlags.Component); } export function filterQueryId(queryId: number): number {