Does `changeDetection: ChangeDetectionStrategy.OnPush` in angular2 only works in one direction: top->bottom?

后端 未结 2 2046
走了就别回头了
走了就别回头了 2021-01-14 18:12

Consider this plunker

import {Component, OnInit, Input, OnChanges, DoCheck, ChangeDetectionStrategy, EventEmitter} from \'angular2/core\'

@Component({
  sel         


        
2条回答
  •  遥遥无期
    2021-01-14 18:41

    I know it has been a while, but i came across a similar problem. Hence i wanted to stress on the fact that OnPush does not always change the way parent and child component communication works. If the child component's @Input property is an object (reference type) then the only way OnChanges is triggered on the child is when the reference changes (new object is created) regardless of OnPush. OnPush makes more sense for template binding, requesting angular to do value equality or just compare references. Please do correct me if i was wrong.

提交回复
热议问题