Ionic-framework: ion-select always returns string even when value is a number..

Created on 30 Jun 2017  路  5Comments  路  Source: ionic-team/ionic-framework

Ionic version: (check one with "x")
[ ] 1.x (For Ionic 1.x issues, please use https://github.com/ionic-team/ionic-v1)
[ ] 2.x
[x] 3.x

I'm submitting a ... (check one with "x")
[x] bug report
[ ] feature request
[ ] support request => Please do not submit support requests here, use one of these channels: https://forum.ionicframework.com/ or http://ionicworldwide.herokuapp.com/

Current behavior:

I have a select with an object containing an id and a name. The id is a number and the name is a string. The option value is the id and the display value the name. Setting the select model to an existing id which is a number works and the correct preselected name is displayed. However, chosing a different option rwill return the id of the newly select object but not as a number. Instead it will be a string. I manually need to convert it back....

Expected behavior:

The selected value (id) should be returned as a number when it is a number.

Steps to reproduce:

Create select with multiple options being a number. Select a different option will return it as a string...

Related code:

insert any relevant code here

Other information:

Ionic info: (run ionic info from a terminal/cmd prompt and paste output below):

global packages:

    @ionic/cli-plugin-proxy : 1.3.1
    @ionic/cli-utils        : 1.4.0
    Cordova CLI             : 6.5.0
    Ionic CLI               : 3.4.0

local packages:

    @ionic/app-scripts              : 1.3.7
    @ionic/cli-plugin-cordova       : 1.4.0
    @ionic/cli-plugin-ionic-angular : 1.3.1
    Cordova Platforms               : android 5.2.1 browser 4.1.0 ios 4.2.0 windows 4.4.3
    Ionic Framework                 : ionic-angular 3.2.1

System:

    Node       : v6.10.0
    OS         : Windows 10
    Xcode      : not installed
    ios-deploy : not installed
    ios-sim    : not installed
    npm        : 4.6.1

Most helpful comment

You probably should bind as [value] and not value if that is what you are doing.

All 5 comments

Hello, thanks for opening an issue with us! Would you be able to provide a plunker that demonstrates this issue? Thanks for using Ionic!

You probably should bind as [value] and not value if that is what you are doing.

@AmitMY
Thanks that was it :)

this work for me

<ion-select [(ngModel)]="age">
<ion-option *ngFor="let number of ' '.repeat(100).split('');
let x = index;" value={(x).toString()}}>{{x}}</ion-option>
</ion-select>

Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out.

Was this page helpful?
0 / 5 - 0 ratings