In my Angular application, I have included some lines of TypeScript code which involve Boolean variables in the constructor and an array of objects. Each object in this array contains input variables.
selftest: boolean;
failed: boolean;
locoStateItems = [
{
name: 'FAILED',
isSelected: this.failed
},
{
name: 'SELFTESTED',
isSelected: this.selftest
}
When a different function is called later on:
toggleMe(name: string){
if (name === 'FAILED') {
this.failed = !this.failed
} else if(name === 'SELFTESTED'){
this.selftest = !this.selftest;
}
}
The displayed locoStateItems in the DOM do not get updated automatically unless I explicitly assign values as follows:
locoStateItem[0].isSelected = this.failed;
locoStateItem[1].isSelected = this.selftest;
I am looking for an explanation for this behavior and suggestions on how to avoid it. Can someone help?