I've a very strange issue in my angular application.
// these are class attributes
tenants: any[] = [];
@Input() onTenantListChange: EventEmitter<Tenant[]>;
ngOnInit(): void {
this.onListChange.subscribe(data => {
if (data !== undefined && Array.isArray(data)) {
console.log("iniziale", data)
this.tenants = [];
for (let t of data) {
console.log(" t ",t)
this.tenants.push({
title: t.name,
value: t.id,
});
}
console.log(this.tenants);
}
});
}
While the first console log shows the updated list, the console.log(" t ",t) shows different value (the previous value of that element, also if i've reinitialized the list to [] befor assigning new values. After two invocation of this event, the edit is captured
As you can see, the Firefox console shows "old value" as the preview, but if I expand the log message, there is the correct value inside
Note: insertion and delete in the data array works, the problem comes when i want to update an existing element
There are of course some walkaround ( I can duplicate the onListChange event trigger), but I cant' figure out where is the real problem whit this loop
Thank you very much for your suggestions
I expect that the console.log inside the for loop shows the same element than the console.log("iniziale", data) I've tyed different type of loop: for (let a of data) data.foreach() for (let i = 0; i< data.length; i++) {}
The output is the same