Home > front end >  ngFor detection from firebaes
ngFor detection from firebaes

Time:12-14

I have a page chat, with different person who the user have chat with the last message date.

getFunction from firebase work as well , I can see the new array in the consol with right information , but in the html page , I need to change view and come back to get right information , I have test changeDetection but it dont Work ,I have test ngzone.run() it work but with delay ..;

this.usersList.push({user:resulta.data(),message:resultaa.data()});

The html

<ng-container *ngFor="let usr of usersList">

CodePudding user response:

instead of push try to spread it;

this.usersList = [
...this.usersList,
{
user:resulta.data(),
message: resultaa.data()
}]

CodePudding user response:

With this line this.changeDetectorRef.detectChanges after the array-push, it doesn‘t work?

The problem is, that Angular's change detection mechanism doesn’t handle the content change of an array (push/pop). So you must manually notify Angular about a change.

The official documentation about Angular-ChangeDetector you can read here

Another way, is with slice(), where you can see on this stackoverflow answer or this.

  • Related