Angular 2 do not refresh view after array push in ngOnInit promise

后端 未结 2 1826

I created a NativeScript app with angular 2, i have an array of objects that i expect to see in the frontend of the application. the behaviour is that if i push an object in

2条回答
  •  滥情空心
    2021-01-17 12:00

    The change detection is based on references, and pushing an element to an array will not trigger it. Try updating the reference like this:

    this.stories.push(story);
    this.stories = this.stories.slice();
    

提交回复
热议问题