How to set the value of radio button alert in Ionic 2

Viewed 2161

I have radio button alert that contain more than 12 options and I want to check the option that is equal than my variable value.

I was use if statement to did this thing with a less than 4 options. But now I have more than 12 option so I wish there is easier way to check the value of my variable and select the equal option.

---edit---

This is a part of my html

<button ion-button clear full (click)="selectColor(x.color)">{{x.color}}</button>

.ts Function ( I want a better way to select the radiobutton of alert (if any) )

selectColor(color){
    let alert1 = this.alertCtrl.create();
alert1.setTitle('Color Theme');
    if(color=="red"){
        alert1.addInput({
            type: 'radio',
            label: 'Red',
            value: 'red',
            checked: true
        });
    }else{
        alert1.addInput({
            type: 'radio',
            label: 'Red',
            value: 'red',
        });
    }
    if(color=="pink"){
        alert1.addInput({
            type: 'radio',
            label: 'Pink',
            value: 'pink',
            checked: true
        });
    }else{
        alert1.addInput({
            type: 'radio',
            label: 'Pink',
            value: 'pink'
        });
    }
    if(color=="purple"){
        alert1.addInput({
            type: 'radio',
            label: 'Purple',
            value: 'purple',
            checked: true
        });
    }else{
        alert1.addInput({
            type: 'radio',
            label: 'Purple',
            value: 'purple'
        });
    }
    if(color=="blue"){
        alert1.addInput({
            type: 'radio',
            label: 'Blue',
            value: 'blue',
            checked: true
        });
    }else{
        alert1.addInput({
            type: 'radio',
            label: 'Blue',
            value: 'blue'
        });
    }
    ...
alert1.addButton('Cancel');
alert1.addButton({
  text: 'Okay',
  handler: data => {
            ...
  }
});
alert1.present();
}
1 Answers
Related