angular - 用于 ngIf 和传递数据的 AsyncPipe
问题描述
在多个绑定中使用 AsyncPipe 是不好的做法吗?我有一个带有 observable 的组件,我将它与 *ngIf 一起用作数据输入,就像这样
<sample-component
ngIf="sampleObs$ | async"
[data] = "sampleObs$ | async"
></sample-component>
它按预期工作,我只是想知道这是否是一种好的做法,因为我是 Angular 的新手
解决方案
我建议使用 async as
ngIf="sampleObs$ | async as sampleObs"
然后下一次调用您只需使用 sampleObs。
推荐阅读
- mysql - 我可以在 CAST() 方法中使用 SUBSTR() 吗?
- foreach - Neo4J - 路径存在时的 FOREACH 案例,删除关系
- php - 从后端源代码上传后如何激活 wordpress 插件
- dns - 为一台主机添加多个 IP 地址时,JMeter DNS 缓存管理器不起作用
- elasticsearch - 根据日期过滤elasticsearch中的查询URI
- amazon-web-services - Terraform - 如何在对象列表上使用 for_each 循环来创建资源
- sql - 在外键中引用多个列会影响 SQL Server 的性能吗?
- maven - 在 pom.xml 中为 Kotlin 中的 Spring Boot 项目指定 Main 类
- performance - 性能改进 jsf
- xamarin - 导航时是否处理 View-ViewModel