angular - Angular 9强制异步管道嵌套在ngIf异步管道中
问题描述
<ng-container *ngIf="condition$ | async">
{{ value$ | async }}
</ng-container>
当 condition$ 在 false 之后发出 true 时,如何强制视图显示最新值?
更新
condition$ 和 value$ 都派生自同一个 formGroup.valueChanges,不能是 BehaviorSubject 的实例。
解决方案
您可以通过shareReplay
在value$
observable 上添加 a 来做到这一点:
<ng-container *ngIf="condition$ | async">
{{ value$ | async }}
</ng-container>
value$ = obs$.pipe(
shareReplay(1)
);
或通过使用BehaviorSubject
或ReplaySubject
推荐阅读
- react-native - 什么反应本机组件以创建带有子项的列表
- php - 我怎样才能在laravel中放置计数器?
- python - 如何从数据库中获取与值列表匹配的记录?
- reactjs - antd 中的 getFieldDecorator 是什么,React 中的 getFieldDecorator 有什么用?
- jakarta-ee - 是否有 ManagedExecutorService 队列限制?
- mysql - 如何更新 MongoDB BI 连接器中的超时设置
- python-3.x - 如何使用python对二进制图像中的列和行像素求和
- python - 我正在使用 selenium 抓取一个网站,beautifulsoup。需要总数。网站中的页面或其他导航页面的方式
- c++ - QSyntaxHighlighter 不会创建 QTextFragments
- r - 闪亮仪表板中 valueBox() 中的两列