Quantcast
Channel: Ionic Forum - Latest topics
Viewing all articles
Browse latest Browse all 70432

Set initial value on ion-select when ngModel is string but ion-select-option "value" is an integer

$
0
0

@trfletch wrote:

I have an ion-select setup as follows, the “attribute.value” is a string but the “option.id” on each ion-select-option is an integer, I need to set the initial value of the select based on “attribute.value”. What I have below worked fine on Ionic 3 but on Ionic 4 and Ionic 5 this doesn’t work, I assume because one is a string and one is an integer so it doesn’t think that they match, I believe on Ionic 3 it must have just converted the [value] on an ion-select-option to a string by default.

The “attributes” I am using are dynamic so they can be a string or an integer when they come from the datasource, therefore, I do not have the option of just changing it so that “attribute.value” is instead an integer when it reaches the page.

I effectively need a way of converting the “attribute.value” to an integer within the HTML in [(ngModel])] so that it matches with the correct ion-select-option and sets the correct initial value. How can I do this?

<ion-select [(ngModel)]="attribute.Value" interface="popover">
  <ion-select-option *ngFor="let option of attribute.Options" [value]="option.Id">{{option.Name}}</ion-select-option>
</ion-select>

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 70432

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>