2017-06-14 90 views
0

我正在嘗試使用ngFor從WebApi讀取列表,但它不適用於我。Angular 2閱讀列表與ngFor視圖?

export class MembershipPage { 

memberships: any = []; 


constructor(public navCtrl: NavController, public authservice: AuthService) { 

} 


ionViewDidEnter() { 
    this.authservice.getmembers().then(
     data => { 
      this.memberships.push(data); 

     } 
    ); 
} 

和我'從視圖調用諸如this`

<ion-content> 
    <ion-list> 
    <ion-item *ngFor="let member of memberships">{{member.Name}} 
    </ion-item> 
    </ion-list> 

enter image description here

讓我的離子項我的數據[對象對象。有什麼問題?我不明白。

+0

是否有任何錯誤消息?可能你的'member'對象沒有'name'屬性。 – Duannx

+0

沒有錯誤消息,是的,我的名單中有名稱屬性。 –

+0

你的'數據'是怎麼樣的?嘗試'console.log(data)'來查看它。 – Duannx

回答

1

試試這個:

ionViewDidEnter() { 
    this.authservice.getmembers().then(data => { 
     this.memberships = data; 
    }); 
} 
+0

Ohh god來看到它。感謝它的運作良好。 –

+0

很高興幫助。 :) –