I am listening to changes on an object property with help of ngDoCheck The implementation is like below
differ: any;
pageSettings:SelectionSettings;
where SelectionSettings is
export interface SelectionSettings {
boolPpt: boolean;
maxRows: number;
startIndex:number;
valuesToSelect: Colum[];
}
The property valuesToSelect is an array of items and is dynamic in nature. [ Items can be added to removed from the list as well as items can be updated ]
ngDoCheck initialization is like below
constructor( private differs: KeyValueDiffers) {
this.differ = differs.find({}).create();
this.initializeSettings();
}
ngDoCheck() {
var changes = this.differ.diff(this.pageSettings);
if (changes) {
console.log('changes detected');
changes.forEachChangedItem(r => console.log('changed ', r.currentValue));
changes.forEachAddedItem(r => console.log('added ' + r.currentValue));
changes.forEachRemovedItem(r => console.log('removed ' + r.currentValue));
} else {
console.log('nothing changed');
}
}
initializeSettings() {
this.pageSettings = {
boolPpt: false,
maxRows: 100,
startIndex: -1,
valuesToSelect: [
{
name: "sadsa",
index: -1,
type: "string",
bgcolor:"#0000CD"
},
{
name: "xxzc",
index: -1,
type: "string",
bgcolor:"#1000CD"
}
]
}
}
The updation of pageSettings occured at different places inside component, like on click event of a table cell or checkbox change event etc
This is firing for all changes of properties except array valuesToSelect . Whenever I am adding new items or remove items of the property SelectionSettings.valuesToSelect , the changes are getting detected.But if we make an updation of already existing item inside SelectionSettings.valuesToSelect , ngDoCheck is not detecting any changes.
How can i detect or listen to changes of all properties of SelectionSettings along with child array properties