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

107
Views
Angular Javascript return the value of dynamic options on select change

I have a select input and I am using *ngFor on the options to let the user select from an dynamic array I am getting from the database

<select formControlName="destination_id" (change)="onSelectDestination($any($event.target).value)"
    <option *ngFor="let destination of destinations" [ngValue]="destination.id" class="p-3">
        {{ destination.name }}
    </option>
</select>

The function

onSelectDestination(id: any) {
  console.log(id);
}

The problem here is that returns the index of the item and the value

for example: if I chose the third item in the select input it returns this 2: 27

2: is the index and 27 is the id I want

I used substr(3, 2) but it's making problems when the index or the id is bigger than two or three letters

What is the best practice to do this?

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

0

Can you try to replace [value] in place of [ngValue]

value is refer to string and ngValue reference to object which includes the index + 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!