【发布时间】:2017-07-24 14:52:56
【问题描述】:
首先我在 macOS 上使用 Ionic 3.x。
我正在尝试将一些数据推送到数组中。
在我定义的导出类中。
export class HomePage {
tables: any[]
//...
addTable(){
let prompt = this.alertCtrl.create({
title: 'Add Table',
subTitle: 'Enter the table number',
inputs: [{
name: 'tableNumber',
placeholder: 'Number',
type: 'number'
}],
buttons: [
{
text: 'Cancel'
},
{
text: 'Add',
handler: data => {
let table = {
number: data.tableNumber,
name: 'occupied'
}
alert('Success');
this.tables.push(table);
}
}
]
});
}
当我在 Ionic 实验室测试应用程序并添加一个表时,它给了我错误:运行时错误 _this.tables 未定义。
显示“成功”警报,因此应用程序在 this.tables.push(table); 处崩溃; ,但我不知道为什么。
【问题讨论】:
标签: angular typescript ionic2 ionic3