简体   繁体   中英

AsyncPipe used for ngIf and Passing Data

Is it bad practice to use AsyncPipe in multiple bindings? I have a component that takes an observable and I am using it as a data input along with *ngIf like so

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

It works as expected, I was just wondering if this was an okay practice as I am new to Angular

I would suggest using async as

ngIf="sampleObs$ | async as sampleObs"

Then the next call you just use sampleObs.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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