有没有办法延迟ngx-bootstrap手风琴的打开?


<accordion [closeOthers]=true>
<accordion-group *ngFor="let activity of activities" [heading]="activity.Name" (click)="openPanel(activity)" (isOpenChange)="openStatusChange($event)">
<ul *ngFor="let chemical of chemicals">
<li>{{chemical.BrandName}}</li>
</ul>
<div *ngIf="!chemicals?.length > 0">No chemicals associated with this activity type.</div>
</accordion-group>
</accordion>

单击手稿标头时,它会打开并运行并触发 'openPanel((' 这是一个 http.get,然后填充面板。 如果数组返回空,*ngIf 将显示"无关联内容"消息。

问题是手风琴打开的时间和数组被填充的时间之间存在非常轻微的滞后,因此当手风琴打开时,化学数组总是空的。 这使得"没有关联的东西"消息出现大约半秒钟,然后填充列表。 所以我想知道是否有办法延迟打开直到填充数组,或者欢迎建议。

你可以对 ngIf 使用布尔标志或函数。在 http 承诺返回成功时设置标志,这样 ngIf 仅在解析 http 调用承诺后触发。

像这样:

http.get('url').subscribe(response => {
show = true;
});

最新更新