簡體   English   中英

Promise和異步管道和Angular ngfor

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM