[英]Angular2 async pipe not working in ngfor
我在 Angular2 中遇到異步管道問題,當我在*ngFor
使用它時。
這里有一些代碼:
這是模板
<li *ngFor="#obj of _filtersPageState | async">
hello world
</li>
_filtersPageState
變量聲明為:
private _filtersPageState: Observable<any> = new Observable<any>();
它通過使用@ngrx/store
的select
函數初始化:
this._filtersPageState = store.select('FiltersPageState');
this._filtersPageState.subscribe(v => console.log(v));
商店內的FiltersPageState
對象是通過 http 請求填充的,如果我在控制台日志中打印@ngrx/store
對象,我可以看到 get 請求已正確執行。
我的問題是,當async
管道放置在ngFor
,組件無法加載並且我在 Chrome 控制台中沒有收到任何錯誤。
如果我寫{{_filtersPageState.value | async}}
{{_filtersPageState.value | async}}
在 html 模板中, Observable
的值顯示正確。
我正在玩測試版 13
任何線索或建議? 謝謝!
編輯
我注意到如果我寫{{_filtersPageState| async}}
{{_filtersPageState| async}}
在模板中,同時我寫了一個ngFor
(即使在沒有async
管道的簡單數組上循環,我的組件(悄悄地)
編輯 2
我想在拼圖中添加另一個圖塊。
以下模板破壞了組件:
{{_filtersPageState | async}}
<li *ngFor="#obj of simpleArray">
{{obj}}
</li>
就像async
和ngFor
不想在一起一樣:(
編輯 3
我發現 ngFor 中沒有管道在工作:
<h1 *ngFor="#element of filtersPageState|async">{{element}}</h1>
<h1 *ngFor="#element of simpleArray|uppercase">{{element}}</h1>
<h1 *ngFor="#element of simpleArray">{{element|uppercase}}</h1>
<h1 *ngFor="#element of simpleArray|aaaaaaaaa">{{element}}</h1>
在所有四種情況下(還有aaaaaaaaa
是一個不存在的管道),我的組件無法加載且沒有錯誤。
我解決了這個問題。
我包含在 Angular 2 的縮小版本中,一旦我包含了 angular2.dev.js,一切都開始工作了。
謝謝
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.