解决方法
由于通过使用带有选项的对象创建警报,我们可以使用该对象创建具有数组名称的单选按钮.
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(); } }
希望这可以帮助 :)