NG2 - 原始值更改后原始组件的输入未更新

时间:2017-06-26 10:54:09

标签: binding angular2-template angular2-changedetection

我正在尝试使用NG2绑定但由于某种原因,当我有多个嵌套的@Input数据时它不起作用 我已阅读并尝试过以下解决方案: Angular 2 - View not updating after model changes

但没有运气。 我基本上有3个组件(父 - >孩子 - >孙子) 父项有一个数据字段,子项和孙子将其作为输入。 原始值没有问题 但是当我尝试在父组件中更新此值时,子项和孙子没有更新。

它符合以下简单组成部分的精神:

 @Component({
 selector: 'parent',  
 template: '<button (click)="updateData()">
             <child [data]="data"></child>'
 })

 export class ChildComponent {  var data = { a : 0};
     click() { this.data.a+=1; }     
 }

 @Component({
 selector: 'child',  
 template: '<grand [data]="data"></grand>' })

 export class GrandComponent {  
     @Input data:any;     
 }

 @Component({
 selector: 'grand',  
 template: '<div>{{data.a}}</div>' })

 export class ParentComponent {  
     @Input data:any;     
 }

0 个答案:

没有答案