Juliatzin
Juliatzin

Reputation: 19695

Select default value in select dropdown with Angular 6

I would like to select default value ( 484 which is Mexico), but the first item get selected.

In the text, I print all value, and they are all OK (country.id === tournament.venue.country_id condition is working)

Here is my code, I am not using reactive forms:

<select class="form-control select-lg" id="country_id" name="country_id" [(ngModel)]="tournament.venue.country_id">
    <option *ngFor="let country of countries"
        [selected]="country.id === tournament.venue.country_id"
        [ngValue]="tournament.venue.country_id">
        {{ country.name }} {{ country.id }} {{ country.id === tournament.venue.country_id }}
    </option>
</select>

What am I doing wrong ?

Upvotes: 0

Views: 2264

Answers (1)

Sachila Ranawaka
Sachila Ranawaka

Reputation: 41427

ngValue should be country id

 [ngValue]="country.id">

Upvotes: 3

Related Questions