无法读取未定义错误

时间:2017-07-14 22:26:10

标签: javascript angularjs ionic-framework ionic2

起初我在.push的IDE中出错了,我将listaOrdenada类型更改为any,没有错误但我在控制台中出错,无法读取未定义的属性推送

import {Component, OnInit} from '@angular/core';
import { NavController, NavParams } from 'ionic-angular';
import {HomePage} from "../home/home";
import {ElegiritemsPage} from "../elegiritems/elegiritems";
import {Articulo} from "../../Data/articulo.interface";

@Component({
  selector: 'page-lista-terminada',
  templateUrl: 'lista-terminada.html',
})
export class ListaTerminadaPage implements OnInit{
  home=HomePage;
  elegirItem=ElegiritemsPage;
  listaFinal : Articulo[] = [];
  listaOrdenada : Articulo[] = [];

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

  ngOnInit(){
    this.listaFinal = this.navParams.data;
    for (var i=0; i < this.listaFinal.length; i++) {
      console.log(this.listaFinal[i]);
      this.listaOrdenada[this.listaFinal[i +1].pasillo].push(this.listaFinal[i]);
    }
  }

}

1 个答案:

答案 0 :(得分:1)

您正试图访问一个不存在的数组。

this.listaOrdenada[this.listaFinal[i +1].pasillo].push(this.listaFinal[i]);

i + 1正在尝试访问超出范围的索引。