Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

181
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!