Consider this plunker
Grandchild Component
<button (click)="back2click()"></button>
@Input() from2;
@Output()
back2 = new EventEmitter<any>();
back2click() {
this.back2.emit('hi');
}
Child Component
changeDetection: ChangeDetectionStrategy.OnPush,
<my-app-n2 [from2]="from1" (back2)="handleback2($event)"></my-app-n2>
@Input() from1;
@Output() back1 = new EventEmitter<any>();
handleback2() {
this.back1.emit('hi')
}
Parent Component
<my-app-n1 [from1]="from" (back1)="handleback1($event)"></my-app-n1>
handleback1 () {
this.from.name = 'handline4';
}
I see that when button
is clicked
back2click -> emit -> handleback2 -> emit -> handleback1
-> attribute is updated -> all child view are updated
This is confusing since I expect only the parent view to get updated since changeDetection: ChangeDetectionStrategy.OnPush,
is config in child component.
I think I am missing something, can someone point me the right direction?
Thanks