[英]Promise and async pipe and Angular ngfor
Update: 更新:
Below solution of mine is also working. 下面的解决方案也是可行的。 I had a local storage
corruption or something like that.That was the reason for not working. 我发生local storage
损坏或类似问题,这就是无法正常工作的原因。
Question: 题:
Can you tell me how to use promise
/ async
pipe and ngfor
? 你能告诉我如何使用promise
/ async
管道和ngfor
? I have tried as shown below.But it is not working. 我已经尝试如下所示。但是它不起作用。
html html
<ion-item *ngFor="let c of contacts | async">
<ion-label fixed>c.name</ion-label>
</ion-item>
ts ts
contacts: Promise<Contact[]>;
constructor() {
this.getContacts()
}
getContacts() {
this.contacts = this.storage.get('contacts').then((val: Contact[]) => {
console.log('log', val);
return val;
});
}
try this on your .ts
file: 在您的.ts
文件上尝试一下:
getContacts() {
this.contacts = this.storage.get('contacts');
}
this way in your html the async pipe will subscribe to the promise 这样在您的html中,异步管道将订阅promise
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.