sqllite ionic 2无法读取未定义的属性推送

时间:2018-06-26 00:35:30

标签: angular sqlite ionic2 ionic3 ionic-native

    export class SearchHistoryList {

  public names:[Object];



  constructor(public navCtrl: NavController, public productServiceProvider: ProductsServiceProvider, private sqlite: SQLite) {
    this.getDBData();

  }

  private getDBData() {
    this.sqlite.create({
      name: 'ionicdb.db',
      location: 'default'
    }).then((db: SQLiteObject) => {
      db.executeSql('SELECT * FROM searchHistory',[])
        .then(res => {
          if (res.rows.length > 0) {
            for(let i=0; i <res.rows.length; i++) {

              this.names.push({
                id: res.item(i).rowid,
                name: res.item(i).searchItem,
                time: res.item(i).date
              });
            }
          }
        })
        .catch(e => console.log(e));
    });
  }
}

我正在尝试读取我的数据库并在我的页面上创建要与ngFor一起使用的对象数组。我收到“ TypeError:无法读取未定义的属性'push'” 。到底是怎么回事?

0 个答案:

没有答案