用于ngIf和传递数据的AsyncPipe



在多个绑定中使用AsyncPipe是不是一种糟糕的做法?我有一个组件,它接受一个可观察到的,我将它与*ngIf like so 一起用作数据输入

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

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

我建议使用异步作为

ngIf="sampleObs$ | async as sampleObs"

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

最新更新