繁体   English   中英

用于 ngIf 和传递数据的 AsyncPipe

[英]AsyncPipe used for ngIf and Passing Data

在多个绑定中使用 AsyncPipe 是不好的做法吗? 我有一个接受 observable 的组件,我将它与 *ngIf 一起用作数据输入

<sample-component 
   ngIf="sampleObs$ | async"
   [data] = "sampleObs$ | async"
></sample-component>

它按预期工作,我只是想知道这是否是一个好的做法,因为我是 Angular 的新手

我建议使用 async 作为

ngIf="sampleObs$ | async as sampleObs"

然后下一次调用您只需使用 sampleObs。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM