0

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">

2 Answers2

0

instead of push try to spread it;

this.usersList = [
...this.usersList,
{
user:resulta.data(),
message: resultaa.data()
}]
Talha Akca
  • 394
  • 2
  • 8
0

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.

SwissCodeMen
  • 4,222
  • 8
  • 24
  • 34
  • this.changeDetectorRef.detectChanges work , but with delay, blank array and after 2 seconde it comme with right information – testerdev78500 Dec 14 '21 at 08:35