2017-11-06 4 views
0

업데이트 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; 
    }); 
    } 

답변

2

당신의 .ts 파일이 시도 :

getContacts() { 
    this.contacts = this.storage.get('contacts'); 
} 

비동기 파이프가 T로 구독됩니다 HTML에서이 방법 그는 약속한다

+0

고맙습니다. 이것은 작동 중입니다 :) – Sampath

관련 문제