From 64beae95275eae62e0e26b1ee834ad32cabf2d0d Mon Sep 17 00:00:00 2001 From: Tobias Bosch Date: Tue, 21 Mar 2017 10:44:11 -0700 Subject: [PATCH] fix(core): mark components for check when host events trigger. (#15359) Fixes #15352 PR Close #15359 --- packages/core/src/view/util.ts | 5 ++++- packages/core/test/linker/integration_spec.ts | 12 ++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/packages/core/src/view/util.ts b/packages/core/src/view/util.ts index 4e13eb7506..559d38c7ab 100644 --- a/packages/core/src/view/util.ts +++ b/packages/core/src/view/util.ts @@ -124,7 +124,10 @@ export function markParentViewsForCheck(view: ViewData) { export function dispatchEvent( view: ViewData, nodeIndex: number, eventName: string, event: any): boolean { - markParentViewsForCheck(view); + const nodeDef = view.def.nodes[nodeIndex]; + const startView = + nodeDef.flags & NodeFlags.ComponentView ? asElementData(view, nodeIndex).componentView : view; + markParentViewsForCheck(startView); return Services.handleEvent(view, nodeIndex, eventName, event); } diff --git a/packages/core/test/linker/integration_spec.ts b/packages/core/test/linker/integration_spec.ts index d0a44f2a9d..1e4758d66a 100644 --- a/packages/core/test/linker/integration_spec.ts +++ b/packages/core/test/linker/integration_spec.ts @@ -623,26 +623,29 @@ function declareTests({useJit}: {useJit: boolean}) { fixture.detectChanges(); expect(cmp.numberOfChecks).toEqual(1); - cmpEl.children[0].triggerEventHandler('click', {}); - // regular element + cmpEl.children[0].triggerEventHandler('click', {}); fixture.detectChanges(); fixture.detectChanges(); expect(cmp.numberOfChecks).toEqual(2); // element inside of an *ngIf cmpEl.children[1].triggerEventHandler('click', {}); - fixture.detectChanges(); fixture.detectChanges(); expect(cmp.numberOfChecks).toEqual(3); // element inside a nested component cmpEl.children[2].children[0].triggerEventHandler('click', {}); - fixture.detectChanges(); fixture.detectChanges(); expect(cmp.numberOfChecks).toEqual(4); + + // host element + cmpEl.triggerEventHandler('click', {}); + fixture.detectChanges(); + fixture.detectChanges(); + expect(cmp.numberOfChecks).toEqual(5); }); it('should not affect updating properties on the component', () => { @@ -1870,6 +1873,7 @@ class EventCmp { @Component({ selector: 'push-cmp', inputs: ['prop'], + host: {'(click)': 'true'}, changeDetection: ChangeDetectionStrategy.OnPush, template: '{{field}}
'