I created a NativeScript application with angular 2, I have an array of objects that I expect to see in the frontend of the application. the behavior is that if I push an object into an array directly inside ngOnInit (), it works, but if I create a promise in ngOnInit (), this will not work. here is the code:
export class DashboardComponent { stories: Story[] = []; pushArray() { let story:Story = new Story(1,1,"ASD", "pushed"); this.stories.push(story); } ngOnInit() { this.pushArray();
relative html:
<Label *ngFor="let story of stories" [text]='story.message'></Label>
when the application starts, I see only one click, but I created a button that launches "console.log (JSON.stringify (this.stories)); and at that moment, when I click the button, ui seems to detect a changed array. and another pushed object appears.
EDIT:
I created a simpler example in this thread: Angular 2: when I change a variable in a promise. in ngOnInit view is not updated
angular es6-promise nativescript angular2-nativescript
Andrea Veronesi
source share