Работает ли `changeDetection: ChangeDetectionStrategy.OnPush` в angular2 только в одном направлении: top-> bottom?
Учти этоplunker
import {Component, OnInit, Input, OnChanges, DoCheck, ChangeDetectionStrategy, EventEmitter} from 'angular2/core'
@Component({
selector: 'child11',
template: `
<button (click)="change_obj()">Button in Child11</button>
<div>This is child11: {{my_obj11['name']}}</div>
`,
changeDetection: ChangeDetectionStrategy.OnPush
})
export class Child11 {
@Input()
my_obj11: Object;
change_obj(){
this.my_obj11['name'] = 'some other name';
}
}
@Component({
selector: 'child1',
template: `
<child11 [my_obj11]="my_obj1"></child11>
<div>This is child1: {{my_obj1['name']}}</div>
`,
changeDetection: ChangeDetectionStrategy.OnPush,
directives: [Child11]
})
export class Child1 {
@Input()
my_obj1: Object;
}
@Component({
selector: 'parent',
template: `
<div>
<child1 [my_obj1]="my_obj" ></child1>
This is my_obj in parent: {{my_obj['name']}}
</div>
`,
directives: [Child1]
})
export class App {
my_obj: Object = {'name': 'name1'};
}
Вот отношения между компонентами
Parent
|
Child1
|
Child11
Мы отмечаем, чтоChild1
иметьchangeDetection: ChangeDetectionStrategy.OnPush
Приведенный выше код довольно прост,parent
отправить объектchild1
который отправляет точно такой же объектchild11
.
child11
затем обновите примитив объекта.
Мы видим, что обаparent
а такжеchild1
объект обновляется, хотяchild1
иметьchangeDetection: ChangeDetectionStrategy.OnPush
Я предполагаю, чтоchangeDetection: ChangeDetectionStrategy.OnPush
работает только в одну сторону: сверху вниз.
Это правда?
Если так, есть ли причина для этого?