Sweg
April 20, 2020, 3:29pm
1
In my Ionic / Angular app, I am trying to allow users to select a user type when signing up.
For example, I want them to choose whether they are a Customer or a Supplier.
I tried to add these 2 options to an <ion-radio-group>
as part of a reactive form.
I have tried adding formConrolName
to the <ion-radio-group>
, & then using the value of the ion-radio
, but that is not working.
I’m just wondering what is the best work-around option that can allow me to enable this functionality?
in your html add:
<ion-radio-group formControlName="notifyMe">
<ion-item>
<ion-label>Customer</ion-label>
<ion-radio
slot="start"
value="customer"
formControlName="notifyMe"
></ion-radio>
</ion-item>
<ion-item>
<ion-label>Supplier</ion-label>
<ion-radio
slot="start"
value="supplier"
formControlName="notifyMe"
></ion-radio>
</ion-item>
</ion-radio-group>
in your ts add:
myForm: FormGroup;
ngOnInit() {
this.myForm = this.fb.group({
notifyMe: ' customer', //Set Default value to Customer, will change when radio button is pressed
});
}