angular - 当其中一个具有异步管道时,如何在两个条件下实现和 ngif
问题描述
我有一个组件可以接收 [患者] 或 [患者 ID] 作为 @Input 参数
selectedPatient
当它来自搜索结果时有一个值viewOrdersClientId
当它来自另一个页面时有一个值
目前我正在以这种方式显示一个或另一个(作为一种解决方法)
<div *ngIf="selectedPatient | async as patient">
<wss-patient-detail-component [patient]="patient">
</wss-patient-detail-component>
</div>
<div *ngIf="viewOrdersClientId">
<wss-patient-detail-component [patientId]="viewOrdersClientId">
</wss-patient-detail-component>
</div>
我想要一个*ngIf
具有多个条件并传递所需值之一,类似于以下内容:
<div *ngIf="viewOrdersClientId || (selectedPatient | async as patient)">
<wss-patient-detail-component
[patient]="patient"
[patientId]="viewOrdersClientId">
</wss-patient-detail-component>
</div>
当我这样做时,我收到此错误:
“PatientComponent”类型上不存在属性“患者”
有什么方法可以实现只有一个wss-patient-detail-component
而不是我目前的方法?
解决方案
通常,您可以使用 *ngIf 和 pattien 创建“onfly”对象并作为参数传递
<!--see that the *ngIf is always true-->
<div *ngIf="{patient:selectedPatient | async} as data">
<!--you get the value in "data.patient-->
<div *ngIf="data.patient || viewOrdersClientId">
<wss-patient-detail-component [patient]="data.patient" [patientId]="viewOrdersClientId">
</wss-patient-detail-component>
</div>
</div>
推荐阅读
- scala - Spark-shell 无法读取 CSV 文件,在本地模式下超时失败
- python - Python中的All or Nothing操作
- java - 在处理之前检查大文件是否完全上传到目录中
- docker - Ubuntu docker 用户没有 dns 但 root 有
- azure-cosmosdb - 我可以调整此查询以仅显示相关区域设置吗?
- flutter - 可以在一个应用程序中制作多个颤动页面吗?
- grafana - 将 Grafana 警报保存到 SQL 数据库
- python - 你如何强制 Flask 在每个 GET 请求上查询数据库?
- javascript - 给定一个数字从 1 到 a.length 的数组,我如何找到第二次出现的索引最小的第一个重复数字?
- ios - WKWebView 导致内存警告,应用程序被终止