Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

182
Visualizações
Ionic 2, Angular 2 Textbox values in For Loop

Ionic 2 and Angular 2

I have 3 textboxes each one with different ngModel value Home.html file:

 <ion-item>
   <ion-label>Off Peak Usage1:</ion-label>     
   <ion-input type="text" [(ngModel)]="usage.usage1"></ion-input> 
 </ion-item>
 <ion-item>
   <ion-label>Off Peak Usage2:</ion-label>     
   <ion-input type="text" [(ngModel)]="usage.usage2"></ion-input>   
 </ion-item>
 <ion-item>
   <ion-label>Off Peak Usage3:</ion-label>     
   <ion-input type="text" [(ngModel)]="usage.usage3"></ion-input> 
 </ion-item>

I want to do some calculation part on those entered values in textboxes one after other. I want each text box value must be passed one after other. Below is my For loop in Home.ts file:

usage={
    usage1:'',
    usage2:'',
    usage3:''
};
for(let i=1; i<=3; i++)
{
    let total_usage = this.usage.usage[i];
    let total = total_usage * 5;
}

I am getting usage not defined on this.usage.usage[i]

I don't know I am doing correctly or not, can any one help me out with this ?

Thank you.

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Try to access object property like so:

this.usage['usage1']

Your loop will be:

for(let i=1; i<=3; i++)
{
    let total_usage = this.usage['usage'+i];
    let total = total_usage * 5;
}
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda