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


i created nativescript app angular 2, have array of objects expect see in frontend of application. behaviour if push object array directly inside ngoninit() works, if create promise in ngoninit() doesn't work. here code:

export class dashboardcomponent {      stories: story[] = [];       pusharray() {          let story:story = new story(1,1,"asd", "pushed");          this.stories.push(story);      }       ngoninit() {          this.pusharray(); //this shown           var promise = new promise((resolve)=>{              resolve(42);              console.log("promise hit");          });           promise.then(x=> {              this.pusharray(); //this not shown          });      }  } 

the relative html is:

<label *ngfor="let story of stories" [text]='story.message'></label> 

when app starts see 1 push, created button trigger "console.log(json.stringify(this.stories));" , @ moment, when tap button, ui seems detects changed array, , other pushed object appears.

edit:

i created more simple example in thread: angular 2: when change variable in promise.than in ngoninit view doesn't refresh

the change detection based on references, , pushing element array not trigger it. try updating reference this:

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

Comments

Popular posts from this blog

amazon web services - S3 Pre-signed POST validate file type? -

c# - Check Keyboard Input Winforms -