problems with variables type using ion-input

0

Performing a project with ionic 3 I had a very strange problem, I'm working on my file ts I use two variable of type number, but in my file html I have two elements <ion-input> of type="number" and with the directive [(ngModel)] , but when modifying the values of the variables by keyboard my file ts begins to understand these variable as type string , I leave the code below, the subject is that I compare if one number is greater than another but it gives me unexpected results

page.ts

variable1: number;
variable2: number; 

constructor() {
    var variableMayor
    if(this.variable1 > this.variable2){
        variableMayor = this.variable1 
        console.log('variable mayor es variable1', variableMayor )

    }else{
        variableMayor = this.variable2 
        console.log('variable mayor es variable2', variableMayor )
    }
 }

page.html

<ion-header>

  <ion-navbar>
    <button ion-button menuToggle>
      <ion-icon name="menu"></ion-icon>
    </button>
    <ion-title>Page</ion-title>
  </ion-navbar>

</ion-header>


<ion-content padding>
    <ion-row >

        <ion-col col-6 >
            <h6 >Variable</h6>
            <ion-input [(ngModel)]="variable1" type="number" ></ion-input>
        </ion-col>

        <ion-col col-6 >
            <h6 >Variable</h6>
            <ion-input [(ngModel)]="variable2" type="number" ></ion-input>
        </ion-col>

    </ion-row>
</ion-content>
    
asked by Daniel Enrique Rodriguez Caste 24.11.2017 в 15:58
source

1 answer

0

change the variables

variable1: number;
variable2: number; 

a

variable1: any;
variable2: any; 

since you already have type="number" in the ion-input you should not have to validate that it is number

I do not know if you already solved the error

    
answered by 27.11.2017 в 16:56