I have angular component with array of Objects
export class AlertsConfigListComponent implements OnInit, DoCheck {
@Input() config: ProductAlertConfig[];
And using IterableDiffer to get changes of this array:
constructor(private iterableDiffers: IterableDiffers) {
this.iterableDiffer = iterableDiffers.find([]).create(null);
}
ngDoCheck(): void {
let changes : IterableChanges<ProductAlertConfig> = this.iterableDiffer.diff(this.config);
if (changes) {
this.doSmth();
}
}
It works and I can get changes every time when array is changed. So now my question is. How to check in changes object that array's size is changed, because it is triggered also when I sort this array. There are no properties in IterableChanges object for this purpose.
If I could get new size of array I would do that:
ngDoCheck(): void {
let changes : IterableChanges<ProductAlertConfig> = this.iterableDiffer.diff(this.config);
if (changes && newSize !== oldSize) {
this.doSmth();
}
}
And it would fix the problem, but are there any other solutions?