2017-07-26 124 views
1

我試圖顯示從API獲取的數據列表。 頁面加載時說錯誤數組未定義。但控制檯打印數組。離子視圖不會渲染ng-repeat從API獲取的數據

這是我到目前爲止所做的。

update.html

<ion-item ng-repeat="e in errorList"> 
     <ion-label>{{e.name}}</ion-label> 
     <ion-radio value=""></ion-radio> 
</ion-item> 

我試圖發送的導航PARAMS。呼籲構造和ionViewWillEnter()取回功能

update.ts

export class AboutPage { 
    errorList: any; 
    error: string; 
    errors: {}; 
    nav: NavController; 

constructor(public navCtrl: NavController, public navParams: NavParams, private errorService: ErrorServiceProvider) { 
    this.nav = navCtrl; 
    this.error = ""; 
    this.errors = this.navParams.get('errors'); 
    this.errorList = []; 
} 

ionViewWillEnter() { 
    this.fetchErrors(); 
} 

fetchErrors() { 
    this.errorService.getErrors() 
    .then(data => { 
    this.errorList = data; 
    console.log(this.errorList); 
}); 
} 

selectError() { 
    console.log(this.errors); 
    console.log(this.errorList); 
    } 
} 

回答

0

您在這裏做的,而不是ng-repeat使用愚蠢的錯誤,ngFor,因爲它的角度,還使用了elvis運營商檢查值是否存在

<ion-item ngFor="let e in errorList"> 
     <ion-label>{{e?.name}}</ion-label> 
     <ion-radio value=""></ion-radio> 
</ion-item> 
+0

沒有錯誤。但不運行ng-repeat。 fetchErrors()函數輸出正確的值。但它不會出現在視圖中。 –

+0

@dhanush_c檢查更新的答案 – Sajeetharan

+0

仍然無法正常工作。與elvis操作員一起運行,沒有錯誤。但以正常的方式說undefined沒有name屬性。 –