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

188
Views
¿Cómo puedo optimizar mejor mi función angular?

Necesito su ayuda, tengo un código y necesito optimizarlo, ¿alguien puede saber cómo podría ser esto? Este es mi código:

 handlerChangeInfo(value, fieldName: string) { if (fieldName === 'fullName') { this.billingFields.full_name = value; } if (fieldName === 'address') { this.billingFields.address = value; } if (fieldName === 'postalCode') { this.billingFields.postal_code = value; } if (fieldName === 'city') { this.billingFields.city = value; } if (fieldName === 'stateOrProvince') { this.billingFields.state_or_province = value; } if (fieldName === 'taxId') { this.billingFields.tax_id = value; }

}

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Puede crear un objeto para asignar sus valores de nombre de campo a los nombres de clave de objeto

 const obj = { fullName: 'full_name', address: 'address', postalCode: 'postal_code', city: 'city', stateOrProvince: 'state_or_province', taxId: 'tax_id' } handlerChangeInfo(value, fieldName: string) { if (obj[fieldName]) { this.billingFields[obj[fieldName]] = value; } }
about 4 years ago · Juan Pablo Isaza Report

0

Versión del mapa

 const obj = new Map([ ['fullName', 'full_name'], ['address', 'address'], ['postalCode', 'postal_code'], ['city', 'city'], ['stateOrProvince', 'state_or_province'], ['taxId', 'tax_id'] ]); handlerChangeInfo(value, fieldName: string) { if (obj.get(fieldName)) { this.billingFields[obj.get(fieldName)] = value; } }
about 4 years ago · Juan Pablo Isaza 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!