2017-08-28 4 views
1

Ionic 3でJavaScriptを使用していて、iOSで作業しています。私は、ユーザーが選択するためのラジオオプション付きアラートを実装しようとしています。Ionic 2/3ラジオアラートで値にアクセスする方法

私は、次のコードにアラートで選択されたラジオの値にアクセス/使用して取得することはできません。

let alert = this.alertCtrl.create({ 
     title: 'Specify the reason', 
     inputs: [ 
      { 
      type: 'radio', 
      label: 'label 1', 
      value: '0' 
      }, 
      { 
      type: 'radio', 
      label: 'label 2', 
      value: '1' 
      } 
     ], 
     buttons: [ 
      { 
      text: 'Cancel', 
      role: 'cancel', 
      handler:() => { 
       console.log('Cancel clicked'); 
      } 
      }, 
      { 
      text: 'OK', 
      handler:() => { 
       console.log('OK clicked: '); 
       // I NEED TO GET THE VALUE OF THE SELECTED RADIO BUTTON HERE 
      } 
      } 
     ] 
     }); 
     alert.present(); 

答えて

1

あなたはOKハンドラ内のデータにアクセスすることができます

inputs: [ 
    { 
     name: "myValue", // add a name property 
     type: 'radio', 
     label: 'label 1', 
     value: '0' 
    }, 
    { 
     name: "myValue", // and here 
     type: 'radio', 
     label: 'label 2', 
     value: '1', 
    } 
], 
buttons: [ 
    { 
     text: 'OK', 
     handler: data => { 
      console.log('OK clicked: '); 
      // access through 'data.[nameproperty]' 
      console.log(data.myValue); 
     } 
    } 
] 
1

ますハンドラの無線データを取得します。 Check the docs ..あなたのOkハンドラはデータとしてパラメータを持ちます。

buttons: [ 
     { 
     text: 'Cancel', 
     role: 'cancel', 
     handler:() => { 
      console.log('Cancel clicked'); 
     } 
     }, 
     { 
     text: 'OK', 
     handler: (radiobuttonData) => { 
      console.log('OK clicked: '+ radiobuttonData);//here 
     } 
     } 
    ] 
関連する問題