I am currently working with an array called dataSource in my Angular project. I need to detect and handle any changes that occur when new items are added or deleted from this array. To do this, I have passed the array as a getter setter for @Input change detection in a child component.
Below is my AppComponent :
<div>
<vertital-tabs
[config]="config"
[dataSource]="dataSource" <-- Need to detect Array changes in Child
[(selectedItem)]="selectedItem">
</vertital-tabs>
<div style="background-color: yellow;margin: 10px">
{{ selectedItem | json }}
</div>
</div>
In the ChildComponent (vertical-tabs) :
get dataSource(): any {
return this._dataSource;
}
@Input() set dataSource(value: any) {
this._dataSource = value;
// The setter is not triggered when adding a new item to the array.
// I want it to trigger on clicking the Add New Item button....
debugger;
}
The current issue I am facing is that the setter method is not being called when a new item is added to the array. However, it does work correctly when deleting an item.
Note: Due to having numerous properties as inputs in real scenarios, using ngOnChanges() is not feasible.
Here is a sample implementation I created for reference: https://stackblitz.com/edit/angular-vertical-tabs-component-split-yzynef