Detect change in child component's variable triggered by parent angular 2
Either you make newData
a setter or you implement OnChanges
export class ChildCom {
private _newdata: any = [];
@Input()
set newdata(value) {
// code here
}
}
export class ChildCom implements OnChanges {
@Input() set newdata(: any = [];
ngOnChanges(changes) {
// code here
}
}
https://angular.io/docs/ts/latest/api/core/index/OnChanges-class.html
hint
newdata={{data}}
is fine, but only supports string values
[newdata]=data
supports all types of values.
Here is a link to updated plnkr to explain the same, https://plnkr.co/edit/5ahxWJ?p=preview