fix(core): mark components for check when host events trigger. (#15359)

Fixes #15352

PR Close #15359
This commit is contained in:
Tobias Bosch 2017-03-21 10:44:11 -07:00 committed by Miško Hevery
parent 15a082c74e
commit 64beae9527
2 changed files with 12 additions and 5 deletions

View File

@ -124,7 +124,10 @@ export function markParentViewsForCheck(view: ViewData) {
export function dispatchEvent( export function dispatchEvent(
view: ViewData, nodeIndex: number, eventName: string, event: any): boolean { 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); return Services.handleEvent(view, nodeIndex, eventName, event);
} }

View File

@ -623,26 +623,29 @@ function declareTests({useJit}: {useJit: boolean}) {
fixture.detectChanges(); fixture.detectChanges();
expect(cmp.numberOfChecks).toEqual(1); expect(cmp.numberOfChecks).toEqual(1);
cmpEl.children[0].triggerEventHandler('click', <Event>{});
// regular element // regular element
cmpEl.children[0].triggerEventHandler('click', <Event>{});
fixture.detectChanges(); fixture.detectChanges();
fixture.detectChanges(); fixture.detectChanges();
expect(cmp.numberOfChecks).toEqual(2); expect(cmp.numberOfChecks).toEqual(2);
// element inside of an *ngIf // element inside of an *ngIf
cmpEl.children[1].triggerEventHandler('click', <Event>{}); cmpEl.children[1].triggerEventHandler('click', <Event>{});
fixture.detectChanges(); fixture.detectChanges();
fixture.detectChanges(); fixture.detectChanges();
expect(cmp.numberOfChecks).toEqual(3); expect(cmp.numberOfChecks).toEqual(3);
// element inside a nested component // element inside a nested component
cmpEl.children[2].children[0].triggerEventHandler('click', <Event>{}); cmpEl.children[2].children[0].triggerEventHandler('click', <Event>{});
fixture.detectChanges(); fixture.detectChanges();
fixture.detectChanges(); fixture.detectChanges();
expect(cmp.numberOfChecks).toEqual(4); expect(cmp.numberOfChecks).toEqual(4);
// host element
cmpEl.triggerEventHandler('click', <Event>{});
fixture.detectChanges();
fixture.detectChanges();
expect(cmp.numberOfChecks).toEqual(5);
}); });
it('should not affect updating properties on the component', () => { it('should not affect updating properties on the component', () => {
@ -1870,6 +1873,7 @@ class EventCmp {
@Component({ @Component({
selector: 'push-cmp', selector: 'push-cmp',
inputs: ['prop'], inputs: ['prop'],
host: {'(click)': 'true'},
changeDetection: ChangeDetectionStrategy.OnPush, changeDetection: ChangeDetectionStrategy.OnPush,
template: template:
'{{field}}<div (click)="noop()"></div><div *ngIf="true" (click)="noop()"></div><event-cmp></event-cmp>' '{{field}}<div (click)="noop()"></div><div *ngIf="true" (click)="noop()"></div><event-cmp></event-cmp>'