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

226
Views
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
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!