2017-06-14 44 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

很高兴帮助。 :) –