[英]Angular 5: Updating template in Observable chain not working
如果我有一個組件並想要顯示一個加載器
零件
ngOnInit() {
this.route.params
.do(x => this.contentLoading = true)
.switchMap(x => this.getClientSearchResults())
.subscribe(x => {
this.clientSearchResults = x;
this.contentLoading = false
});
}
模板
<mat-progress-spinner *ngIf="contentLoading" color="accent" mode="indeterminate"></mat-progress-spinner>
加載器將在頁面首次加載時顯示,但是對參數的任何更改將不再顯示加載器。 我可以看到每次使用console.log
運行Observable鏈。 ngZone
仍在運行Observable鏈時是否無法檢測到它?
switchMap
將完成先前的可觀察對象,並切換到新的可觀察對象。 這意味着在發出第一個參數更改后, subscribe
將不再接收將來的更改。
我認為您要使用的是mergeMap
。
https://www.learnrxjs.io/operators/transformation/mergemap.html
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.