ionic-framework: bug: Input type number is not respected
Type: <span ionic-type>bug</span>
Ionic Version: <span ionic-version>2.x</span>
Platform: <span ionic-platform>all</span>
<span ionic-description>Steps to reproduce:
- Create an
ion-inputwithtype="number" - Add
[(ngModel)]and(ngModelChange)to get the Value of the input - Check the type of the value using
typeOf(value) - Type in a number into the input => Type is always a string
Expected behavior: … => Type is a number.
See this plunk as an example: https://run.plnkr.co/plunks/GHBFad/</span>
<span is-issue-template></span>
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 8
- Comments: 28 (12 by maintainers)
I confirmed this is still an issue with latest.
workaround:
Template:
Function:
hope this helps.
@n2lose For me the workaround by @dpsoft works. I’m still hoping for a proper fix though.
I think there are a few issues going on in this one issue. Here’s my attempt at a recap (let me know if anything I said is wrong):
<ion-input type="number">the value is returningstringtype instead ofnumber. I can’t get the original plunker to work currently, thanks @mirkonasato for the plunkers, can reproduce with: http://plnkr.co/edit/EjsP3h?p=preview<ion-input type="number">So our issue is that we pass input type dynamically here: https://github.com/ionic-team/ionic/blob/master/src/components/input/input.ts#L103
Which is broken and reported by this Angular issue: https://github.com/angular/angular/issues/13243
Reopening this since it works without the dynamic binding.
Note to team - it may be blocked by Angular but it’s worth investigating. Maybe we should separate the alert / keyboard issue out.
The underlying issue is with setting the
typedynamically, in input.ts.That doesn’t work with plain Angular either, the value becomes a string after editing it: http://plnkr.co/edit/mG5F636NLpkmj09UPWkd?p=preview
Angular’s NumberValueAccessor directive has
input[type=number]as itsselector. I guess that’s only evaluated when the component is created, and at that point thetypeis not yet set?@shootdaj Good catch with the
emitEvent: false. That is all correct. Basically, this needs to be fixed and there is no good, scalable workaround. This should really be higher on ionic’s priority listSeems we still need to find some workaround to fix it temporary
Any progress on this topic?
The original plunk doesn’t seem to work any more.
Here’s a new one with Ionic 2.0.0-rc.3: http://plnkr.co/edit/EjsP3h?p=preview
Note that this works as expected with plain Angular: http://plnkr.co/edit/rIr9jVkUnIfW1FZIbROx?p=preview