I have an array of objects (let's call it arr
). In one of my component's inputs in the (change)
method I modify one of these object's attribute, but in the view (*ngFor
) nothing changes. I read that Angular2 change detection doesn't check the contents of arrays or object, so I tried these:
this.arr = this.arr.slice();
and
this.arr = [...this.arr];
But the view doesn't change, it still shows the old attribute. In the (change)
method with console.log()
I got the correct array. Weird, but this one works: this.arr = [];
I tried NgZone
and markForCheck()
too.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…