Change detection not registering data changes

前端 未结 2 1039
陌清茗
陌清茗 2021-02-19 01:38

I have an html structure with a component inside a component (forgot the proper word for it).

working basicly like this (largely simplified):

main html:

2条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-19 02:31

    If you use a spread operator instead of push it should work.

    this.data = [...this.data, newItem];
    

    The reason for this is that angular detects a change when the whole object changes, or the reference changes, so a mutation isn't going to trigger it. So rather than mutating the array, you need to make it a new array.

提交回复
热议问题