I am using a simple ngFor loop to display a list:
<a class="list-group-item " *ngFor="let user of chatsLists" (click)="viewChat(user)">
<div class="media chat-list-text py-1" [ngClass]="{'align-items-center': !user.isActiveChat}">
<span class="avatar avatar-md mr-2">
<img [src]="user.userid.userImage" alt="Avatar">
</span>
<div class="media-body">
<h6 class="list-group-item-heading mb-1">{{user.userid.userName}}
</h6>
</div>
</div>
</a>
The data is being retrieved from an API function:
chatsLists: any; //also tried with chatsLists = [];
getChats() {
this.api.getAllChats().subscribe((res: any) => {
if (res.success) {
this.chatsLists = res.data;
this.chatdetails = this.chatsLists[0].messages;
this.showChats = true;
}
})
}
The ngFor loop is not updating when I change the boolean value in the function and it's not reflecting in the HTML file. I have also tried placing a simple conditional statement in the HTML:
<p *ngIf="showChats">Show </p>
Below is the full code of the component.ts file for reference:
this.showChats = true;
// Component code goes here