我正在尝试以JSON的形式从Web API获取用户信息,我知道这不是一个数组,并且ngfor无法读取字符串,但是我不知道如何将其转换为JSON!
我的提供者:
getUsers() {
return new Promise(resolve => {
this.http.get('http://localhost:57527/api/EmployeMenageApi/GetListEmployeMenage')
.subscribe(data => {
resolve(data);
}, err => {
console.log(err);
});
});
}
我的ts:
export class LoginPage {
lang: any;
users: any = [];
items: any;
allData: any[];
constructor(public navCtrl: NavController, public navParams: NavParams, public alertCtrl:
AlertController, public menuCtrl: MenuController, public employeprovider: EmployeMenageProvider) {
this.getUsers();
}
getUsers() {
this.employeprovider.getUsers()
.then(data => {
this.users = data;
this.allData = JSON.parse(this.users);
console.log(this.allData);
});
}
我的HTML:
<ion-item *ngFor="let user of allData">
<ion-thumbnail item-left style="size: 1px">
<img src="{{users.EmpMenage_Photo}}">
</ion-thumbnail>
<ion-label>{{users.EmpMenage_Nom}}</ion-label>