I have a click event (updateExpanded) on my parent, when clicked I fire and event off that goes to the child. the child then subscribes to this event. The problem is that the event gets called 4 times. I have tried everything I could find but just cant seem to see why it gets fired so often when it should only get fired once.
I need to load data in my child component when my parent component gets expanded.
Parent TS
@Output()
isExpandedEvent = new EventEmitter<string>();
updateExpanded(id: string) {
this.isExpandedEvent.emit(id);
console.log(id + " parent opened");
}
ngOnDestroy() {
if (this.isExpandedEvent) {
this.isExpandedEvent.unsubscribe();
}
}
Parent HTML
<ngx-planned-maintenance-detail [model]="plannedMaintenanceRecurring" [index]="i" [expandedEventEmitter]="isExpandedEvent">
</ngx-planned-maintenance-detail>
.........
Child TS
@Input()
expandedEventEmitter = new EventEmitter<string>();
ngOnInit() {
this.expandedEventEmitter.subscribe(data => {
if (data) {
console.log("detail complete");
}
});
}
ngOnDestroy() {
this.expandedEventEmitter.unsubscribe();
}

[index]="i"seems to indicate it shows multiple of the same components. Could this be the cause? - MaartenDev