First I had just this in my ngDoCheck method and works perfectly:
var productChanges = this.differ.diff(this.myProduct);
then decided to check changes on a second model of my component and added this below line:
var companyChanges = this.differ.diff(this.myCompany);
and both changes are chekeced in separate if statements but only last one gets called (companyChanges)
Is this expected behavior? Does ngDoCheck only works for one object per component?
For the sake of clarity here is my full ngDoCheck method:
ngDoCheck() {
var productChanges = this.differ.diff(this.myProduct);
//DOESN'T IT CHECK 2 MODELS LIKE SO BELOW ?
//var companyChanges = this.differ.diff(this.myCompany);
if (productChanges) {
// console.log('Product changes detected');
productChanges.forEachChangedItem((r: KeyValueChangeRecord) => {
if (r.currentValue && r.currentValue != r.previousValue) {
this.filterProduct(r.currentValue, r.key);
}
});
}
EDIT: by reading other questions and answers I feel I need to share this:
In component constructor differ is defined like so:
this.differ = differs.find({}).create(null);
Probably this is what needs to be changed first.