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

228
Visualizações
Why is select option in Angular show wrong value

So, I have userSettings where I have dafaultPreset (which is the id) and I have a list of user presets. And I want to show the default preset in HTML select element, where user can change presets.

In HTML I have a select option like this:

<select class="form-control" name="bg" id="" (change)="patchPreset($event)" 
 [ngModel]="userSettings?.defaultPreset">
  <option value="null" disabled>Select Preset</option>
  <option *ngFor="let preset of userPresets" value="{{preset.id}}">{{preset.name}}</option>
</select>

And in my .ts file, when I add new preset to user, I'm calling an API for getting all user presets and assign again like this: this.userPresets = response;.

In that moment the default value in HTML select element changes to the first element of userPresets, even if the defaultPreset id is not changed. When I refresh the page, then it works fine.

Example

userPresets = [{id:1, name:1}, {id:2, name:2}, {id:3, name:3}];

userSettings.defaultPreset = 2;

And it shows 2 in HTML select element. When I again call API to get all presets and assign to userPresets, then in select element it shows 1. Can somebody explain me where I'm wrong?

about 4 years ago · Juan Pablo Isaza
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