ngx-bootstrap - 有没有办法延迟 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;
});
推荐阅读
- ansible - 如何通过ansible重置root密码
- torch - 如何在丢弃填充标记的同时获取序列的torchtext标记嵌入的平均值?
- python - pandas的链式索引
- python - pyspark 数据框 printschema 到树视图以在 reactjs 树视图中显示 - Python
- r - 如何突出显示ggplot的单个点,即一行?
- phpmyadmin - Phpmyadmin 未检测到现有数据库
- python - 命令引发异常:AttributeError:“NoneType”对象没有属性“名称”
- c# - 创建项目时如何自动生成密钥
- reactjs - 检查图像是否使用 Kotlin/JS for React 加载
- python - 有没有办法阻止 to_dict() 将字符串更新为日期时间?