我正在研究離子項目。這裏按鈕點擊,請求是過程和數據被接收爲示出以下內容:如何在angular2或Ionic中應用* ngFor
public login() {
//this.showLoading()
var test33;
this.auth.login(this.registerCredentials).subscribe(data => {
console.log(data["_body"])
test33 = data["_body"]
console.log(test33)
},
error => {
this.showError(error);
});
}
鑑於:
<ion-row class="logo-row">
<ion-col></ion-col>
<h2 *ngFor="let user0 of test33">{{ user0.name }}</h2>
<ion-col width-67>
<img src="http://placehold.it/300x200"/>
</ion-col>
<ion-col></ion-col>
</ion-row>`
在控制檯I接收到該數據中test33變量爲:
[{"id":1,"role_id":1,"name":"Dr. Admin","email":"[email protected]","avatar":"\/user\/1\/profile\/HR1-dummy-avater.png","password":"$2y$10$iEpnh6pJ09rxH5NFFCVzaewBCxC\/FHZuHnkWA6qUrOBO3tYIBbsVC","remember_token":"VgwXUdIpL6EqW7Fp66VGRPjSKE727Inc4MTseJQq84cTCglkS335KCqVnavu","created_at":"2017-05-25 22:46:10","updated_at":"2017-06-14 05:19:52","is_feature":null}]
但{{user0.name}}
不返回名稱。
請指出我犯錯的地方。
如何將其聲明爲屬性。因爲現在當我註釋掉'var test33'並將'test33'更改爲this.test33'時,在'LoginPage'類型中不存在'Property'test33'的錯誤。' – Mohammed
編輯後的回答爲 –