I am trying to find a way to mark the option as selected in my select but I am not successful.
I tried several solutions found over internet but couldn't find the right implementation.
Does any one have a working example, thanks.
Below (part of) my code
.html
<form [formGroup]="fgForm">
...
<select class="form-control" formControlName="country">
<option value="" [ngValue]="null">Choose your country</option>
<option
*ngFor="let oneCountry of selOptCountries;"
[ngValue]="oneCountry"
>{{oneCountry.name}}</option>
</select>
</form>
.ts (formControl)
// The data comes from an API
this.selOptCountries = [
{"id": 2516, "name": "Austria", "iso2": "AT"},
{"id": 2519, "name": "Belgium", "iso2": "BE"},
{"id": 2523, "name": "Bulgaria", "iso2": "BG"},
{"id": 2601, "name": "Croatia", "iso2": "HR"},
...
{"id": 2636, "name": "Luxembourg", "iso2": "LU"}
...
];
this.fgForm = this.formBuilder.group({
'country': [
{value: datas.country,disabled: false},
[Validators.required]
],
});
datas.country
{id: 2636, name: "Luxembourg", iso2: "LU"}