Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular Ionic 2中的阵列警报_Angular_Typescript_Ionic Framework_Ionic2_Ionic3 - Fatal编程技术网

Angular Ionic 2中的阵列警报

Angular Ionic 2中的阵列警报,angular,typescript,ionic-framework,ionic2,ionic3,Angular,Typescript,Ionic Framework,Ionic2,Ionic3,如何使用数组填充警报列表。例如,如果数组有一组名称 数组=[john,dixy,tom,jared] 我希望弹出警报并显示这些名称,以便从中进行选择。 我在和爱奥尼亚2合作 由于警报是通过使用带有选项的对象创建的,因此我们可以使用该对象创建带有数组名称的单选按钮 import { Component } from "@angular/core"; import { AlertController } from "ionic-angular/index"; @Component({ temp

如何使用数组填充警报列表。例如,如果数组有一组名称

数组=[john,dixy,tom,jared]

我希望弹出警报并显示这些名称,以便从中进行选择。
我在和爱奥尼亚2合作

由于
警报是通过使用带有选项的对象创建的,因此我们可以使用该对象创建带有数组名称的单选按钮

import { Component } from "@angular/core";
import { AlertController } from "ionic-angular/index";

@Component({
  templateUrl:"home.html"
})
export class HomePage {

  private names: Array<string>;

  constructor(private alertCtrl: AlertController) { 
    this.names = [ 'john', 'dixy', 'tom', 'jared']; 
  }

  presentConfirm() {

    // Object with options used to create the alert
    var options = {
      title: 'Choose the name',
      message: 'Which name do you like?',
      buttons: [
        {
          text: 'Cancel',
          role: 'cancel',
          handler: () => {
            console.log('Cancel clicked');
          }
        },
        {
          text: 'Ok',
          handler: data => {
            console.log(data);
          }
        }
      ]
    };

    options.inputs = [];

    // Now we add the radio buttons
    for(let i=0; i< this.names.length; i++) {
      options.inputs.push({ name : 'options', value: this.names[i], label: this.names[i], type: 'radio' });
    }

    // Create the alert with the options
    let alert = this.alertCtrl.create(options);
    alert.present();
  }
}
从“@angular/core”导入{Component};
从“离子角度/索引”导入{AlertController};
@组成部分({
templateUrl:“home.html”
})
导出类主页{
私有名称:数组;
构造函数(专用alertCtrl:AlertController){
this.names=['john','dixy','tom','jared'];
}
presentConfirm(){
//对象,其中包含用于创建警报的选项
变量选项={
标题:“选择名称”,
信息:“你喜欢哪个名字?”,
按钮:[
{
文本:“取消”,
角色:“取消”,
处理程序:()=>{
log('Cancel clicked');
}
},
{
文本:“Ok”,
处理程序:数据=>{
控制台日志(数据);
}
}
]
};
options.inputs=[];
//现在我们添加单选按钮
for(设i=0;i

希望这能有所帮助:)

@sebafereras我尝试了警报内部数组的for循环,以填充警报内部的无线电列表,但不起作用。如果不将for循环放在警报中,则会出现错误。但是如果我把for循环放在外面,它会告诉我阵列警报的大小。好的,谢谢。你是否在尝试实现类似的目标?是和否。我正在寻找,但在一个警报中,不是它自己的页面,也适用于任何试图这样做的人。不能在同一警报中同时使用无线电项目和常规输入。这只是离子2的一个问题,我想我在一个论坛上读到过,他们可能会更新它。到目前为止,只需发出两个警报。