I'm trying to propagate a change from a component to one of its siblings through their parent via an EventEmitter. The change is to the status of a user in an array.
Here's my code:
child1.component.ts (source)
@Output() adminAdded = new EventEmitter<Array<AdminDetails>>();
...
setAdminStatus(index: number, status: string): void {
this.admins[index].status = status;
this.adminAdded.emit(this.admins);
}
parent.component.ts
onAdminAdded(adminDetails: Array<AdminDetails>): void {
Object.assign(this.adminDetails, adminDetails]);
}
parent.component.html
<child1-component (adminAdded)="onAdminAdded($event)"></child1-component>
<child2-component [admins]="adminDetails"></child2-component>
child2.component.ts
adminMails: string[];
@Input() set admins(admins: Array<AdminDetails>) {
if (!admins) {
return;
}
adminMails = admins.filter(x => x.status === 'Active').map(x => x.email);
}
and here I'm displaying the emails of active admins. The issue is that the change only gets as far as the parent component. The breakpoint at Object.assign gets hit, but in the setter, it does not.
I assume it is because the reference to the array is the same and it doesn't recognize the change. Any ideas?