[英]Promise and async pipe and Angular ngfor
更新:
下面的解決方案也是可行的。 我發生local storage
損壞或類似問題,這就是無法正常工作的原因。
題:
你能告訴我如何使用promise
/ async
管道和ngfor
? 我已經嘗試如下所示。但是它不起作用。
html
<ion-item *ngFor="let c of contacts | async">
<ion-label fixed>c.name</ion-label>
</ion-item>
ts
contacts: Promise<Contact[]>;
constructor() {
this.getContacts()
}
getContacts() {
this.contacts = this.storage.get('contacts').then((val: Contact[]) => {
console.log('log', val);
return val;
});
}
在您的.ts
文件上嘗試一下:
getContacts() {
this.contacts = this.storage.get('contacts');
}
這樣在您的html中,異步管道將訂閱promise
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.