arrays - 为什么我的推送方法在使用 Ionic 时不起作用?
问题描述
我正在使用 ionic 3,当我尝试在 mi 数组中推送一个元素时,我遇到了警报控制器的问题。我不知道我的代码有什么问题,我认为我只需要接收参数并推送它来完成操作,但是当我尝试执行我的代码时我只会遇到一个大错误。
很抱歉,我知道我的英语很差。
代码
addPregunta() {
const prompt = this.alertCtrl.create({
title: "Login",
message: "Enter a name for this new album you're so keen on adding",
inputs: [
{
name: "title",
placeholder: "Title"
}
],
buttons: [
{
text: "Cancel",
handler: data => {
console.log("Cancel clicked");
}
},
{
text: "Save",
handler: data => {
const preObj = {
type: "radio",
label: data.title
};
this.preguntas.push(preObj);
this.changeData(data.title);
this.mermaidStart();
}
}
]
});
prompt.present();
}
大批
preguntas: object[];
错误
解决方案
已定义变量 como un array pero no lo has inicializado entonces da error al hacer push。
您已将变量声明为 Array 类型,但您没有对其进行初始化,因此当您尝试将其推入时失败。
推荐阅读
- python - 如何使用 y-ticks(周一→周日)对 matplotlib 图的 y 轴进行排序,对过程中的数据进行排序?
- bash - 终端 Tab 键不会自动完成,而是尝试运行我的脚本
- python - openCV 中的 Mac aalart 弹出窗口
- laravel - 在 Lumen 框架内通过 Mandrill 发送电子邮件
- c - 检查字符串的标记方法
- jenkins - Jenkins unstash 不起作用,但目录不干净
- python - Docker在Dockerfile中编译python文件不要创建pyc
- node.js - 如何在服务器生成的 pdf 中创建复选框?
- go - 为什么我不能将 Error() 用于类型 validator.FieldError
- reactjs - 如何在 react.js 中按钮的 onClick 事件的同一窗口中显示表单