Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

227
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda