繁体   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