离子:未捕获(承诺):TypeError:无法读取未定义的属性“长度”

时间:2018-06-22 07:15:47

标签: angular typescript ionic-framework

这是我的打字稿代码

export class FailedPage {

  failedjobs: Array<any> = [];

  constructor(public navCtrl: NavController, 
              public navParams: NavParams, public jobfailList: JobActionsProvider) {
  }

  ionViewDidLoad() {
    console.log('FailedPage');
    // getting jobs from job-actions file and displaying
    this.jobfailList.getfailedjobList().then((data) => {
      console.log('displaying failed job list');
      for (let values of data) {
        this.failedjobs.push(values);
      }
    });
  }

}

我正面临错误

  

未捕获(承诺):TypeError:无法读取的属性“ length”   未定义的TypeError:无法读取位于的未定义属性“长度”   failed.ts:24

这里的24行是for (let values of data)我该如何解决?

1 个答案:

答案 0 :(得分:0)

api的响应可以是data.data,它取决于您的后端