I got a component named "mainHomeComponent". Inside this component I got a method called "requestForPost". This method is called inside ngAfterViewInit() and when scrollbar reached the bottom of the page.
When the method requestforPost finished I store the result inside a static variabile into AppComponent.
When I move to another controller and come back to the previous one, ngAfterViewInit() method get triggered again. At this time I look for my static variabile and if this one is setted I get it's content instead of sending again a request.
But when my scrollbar reached the bottom of the page again, my json get updated but my DOM doesn't.
Code:
ngAfterViewInit()
{
console.log("after");
if(AppComponent.staticVar.length == 0)
{
this.requestForPost();
}
else
{
this.myList = AppComponent.staticVar;
}
}
requestForPost()
{
...
sendingRequest
...
(success) =>
{
this.myList = this.myList.concat(success);
AppComponent.staticVar = this.myList
})
}
Inside requestForPost method I can see that "myList" get updated but not into DOM.
Thanks for help.
EDIT:
<eleC *ngFor="let item of myList;"></eleC >
EDIT 2 CLOSED:
At the end I managed to do it with:
this.myList = this.myList
I read this solution at: Angular2 ngFor OnPush Change Detection with Array Mutations