Reputation: 61
I am using mat-accordion
. I also request data from the server every second. And because of this, when I try to open the accordion component, it immediately closes.
Is it possible to prevent the accordion from closing, given if I will receive data from the server every second?
ts:
load() {
this.ngUnsubscribe = timer(0, 1000).pipe(
switchMap(() => this._orders.getAllOrders())
).subscribe(orders => {
this.orders = orders
}, error => {
this._toast.error(error.error.message);
})
}
html:
<mat-accordion *ngFor="let order of orders" multi>
<mat-expansion-panel>
<mat-expansion-panel-header>
<mat-panel-title>
{{order.name}}
</mat-panel-title>
</mat-expansion-panel-header>
<p>I'm visible because I am open</p>
</mat-expansion-panel>
</mat-accordion>
Upvotes: 2
Views: 623
Reputation: 2545
try out this.
<mat-accordion *ngFor="let order of orders; trackBy:trackByIdentity" multi>
........
</mat-accordion>
in ts
trackByIdentity(index, item){
return item.name;
}
Upvotes: 3