<ion-select formControlName="FollowUpType"
(ngModelChange)="reset()">
<ion-option value="0">
A
</ion-option>
<ion-option value="1">
B
</ion-option>
</ion-select>
I need this select when I take it's value to be number not string (0 number , or 1 number ) not "0" and not "1". I'm using reactive form :
this.Form = this.formBuilder.group({
FollowUpType: [''],
});
You should bind as [value]
and not value
<ion-select formControlName="FollowUpType" (ngModelChange)="reset()">
<ion-option [value]="0">A</ion-option>
<ion-option [value]="1">B</ion-option>
</ion-select>
What I see here are a couple of options, which both tho requires work, other for styling, other for extra variables. So going for parseInt()
before passing the data to the backend would be preferable.
Option one is to just use select
instead of ion-select
, with that, ngValue
works, which can capture the number. But that requires styling for the select to look like an ionic select.
Option two would be to have two variables and use [value]
in the select instead of select
.
Final option would then be to use an array
values = [{value:0, label:'A'},{value:1, label: 'B'}]
iterate it and use it together with [value]
:
<ion-select formControlName="FollowUpType" (ionChange)="reset()">
<ion-option *ngFor="let val of values" [value]="val.value">
{{val.label}}
</ion-option>
</ion-select>
Demo with all three: http://plnkr.co/edit/dwbttQZTh9JGwKcvFtTX?p=preview
Maybe easiest is to just go with parseInt()
for the value before sending it to the backend.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With