0

Realizando un proyecto con ionic 3 he tenido un problema bastante extraños, estoy trabajando en mi archivo ts utilizo dos variable de tipo numero, pero en mi archivo html tengo dos elementos <ion-input> de type="number" y con la directiva [(ngModel)], pero al modificar los valores de las variables por teclado mi archivo ts comienza a entender estas variable como tipo string, dejo el código a continuación, el asunto es que comparo si un numero es mayor que otro pero me da resultados inesperados

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>
1
  • He comprobado tú código tal cual y funciona bien: ver demo el 24 nov. 2017 a las 17:12

1 respuesta 1

0

cambia las variables

variable1: number;
variable2: number; 

a

variable1: any;
variable2: any; 

como ya tienes type="number" en el ion-input no tendrías que sobre validar que sea numero

no se si ya solucionaste el error

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge you have read our privacy policy.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.