首页 > 解决方案 > 为什么我的推送方法在使用 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[];

错误

在此处输入图像描述

标签: arraysangulartypescriptionic3push

解决方案


已定义变量 como un array pero no lo has inicializado entonces da error al hacer push。

您已将变量声明为 Array 类型,但您没有对其进行初始化,因此当您尝试将其推入时失败。


推荐阅读