Ion-radio checked


#1

i have a ion-radio.

I need that after I click on the option the view close and if I click again to open the view the selected value has to be the last one I clicked on. How do I do this?

Condição de venda
<ion-item>
  <ion-label>À Vista</ion-label>
  <ion-radio  value="avista" (ionSelect)="seleciona(tipo1)" #tipo1></ion-radio>
</ion-item>

<ion-item>
  <ion-label>À Prazo</ion-label>
  <ion-radio  value="aprazo" (ionSelect)="seleciona(tipo2)" #tipo2></ion-radio>
</ion-item>

#2

There are a bunch of ways to persist it, which to choose depends on how persistent you want it to be. Across app shutdown/restart?


#3

no, only when modal close, and open again…


#4

Well, in that case, there must be some page that is presenting the modal. Store the value in an object property of that page, pass it to the modal via NavParams, and get it back via onDidDismiss(). Example here.


#5

open modal:

public openCondicao(){
this.database.verificaCarrinho()
.then((data) => {
let modal = this.modalCtrl.create(PreferenciasPage, {“tipovenda”: this.tipovenda});
modal.onDidDismiss(data => {
this.tipovenda = data;
});
modal.present();
return 0;
});

modal:


Condição de venda
<ion-item>
  <ion-label>À Vista</ion-label>
  <ion-radio value="avista" (ionSelect)="seleciona(tipo1)" #tipo1></ion-radio>
</ion-item>

<ion-item>
  <ion-label>À Prazo</ion-label>
  <ion-radio value="aprazo" (ionSelect)="seleciona(tipo2)" #tipo2></ion-radio>
</ion-item>

public seleciona(tipo){
this.tipovenda = tipo.value;
let data = {tipovenda: this.tipovenda}
this.database.enviaTipoVenda(this.tipovenda)
.then((data) => {
this.database.presentToast(data);
this.viewCtrl.dismiss(data);
})
}

after close modal, i reopen modal again, and the radio is not checked!


#6

if i open modal and choose option OK IT’S WORK(RADIO CHECKED AND CLOSE MODAL). BUT IF I REOPEN MODAL, RADIO NOT CHOOSED…

OPEN MODAL:

public openCondicao(){
      this.database.verificaCarrinho()
      .then((data) => {
         let modal = this.modalCtrl.create(PreferenciasPage, {"tipovenda": this.tipovenda});
         modal.onDidDismiss(data => {
            this.tipovenda = data.tipovenda;
         });
         modal.present();
         return 0;
      });
    }

MODAL:

this.tipovenda = this.navParams.get(‘tipovenda’);

<ion-list radio-group>
    <div>
        Condição de venda
    </div>
    
    <ion-item>
      <ion-label>À Vista</ion-label>
      <ion-radio value="avista" (ionSelect)="seleciona(tipo1)" #tipo1></ion-radio>
    </ion-item>

    <ion-item>
      <ion-label>À Prazo</ion-label>
      <ion-radio value="aprazo" (ionSelect)="seleciona(tipo2)" #tipo2></ion-radio>
    </ion-item>
  </ion-list>
public seleciona(tipo){
    this.tipovenda = tipo.value;
    this.database.enviaTipoVenda(this.tipovenda)
    .then((data) => {
      let obj = {tipovenda: this.tipovenda}
      this.viewCtrl.dismiss(obj);
    })
  }

#7

Typically one binds some property to a radio group with [(ngModel)] as described here.


#8

this check radio auto ?