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

105
Visualizações
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 Respostas
Responde à pergunta

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 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