Calliste Hanriat Calliste Hanriat - 1 year ago 258
TypeScript Question

Get value from input number Angular 2

I'm trying to recover a value from an input with ionic 2 and angular 2.
I want a value of type number.


<ion-label floating>Number</ion-label>
<ion-input id = "choosenNumber" type="number" value=4 ></ion-input>

My TypeScript :

var input_element = <HTMLInputElement> document.getElementById("choosenNumber");
var choosenNumberValue = input_element.valueAsNumber; //does not work !! (valueAsNumber undefined)

Any ideas ?

Answer Source

Okay I've found the solution by using [(ngModel)]. Thanks

Here is the solution : [HTML]

  <ion-label floating>Number</ion-label>
  <ion-input type="number"  [(ngModel)]="chVal" name = "chVal" value=4 ></ion-input>


export class MyClass{

chVal is the good value !!

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download