I'm using reactive forms and I have a select box that comes from an array of objects. I tried to set the default value but it just doesn't set.
My form:
<form [formGroup]="markerForm" (ngSubmit)="onSubmit(markerForm)" novalidate>
<div class="form-group">
<label for="markerType">{{ 'MARKER.LABEL_TYPE' | translate }}</label>
<select class="form-control" formControlName="markerType" >
<option id="markerType" [value]="markerType.id" *ngFor="let markerType of markerTypes">{{markerType.desc}}</option>
</select>
</div>
</form>
Set default value:
const test= [{id:1, desc: 'Restaurants'}, {id:2, desc : 'Fire stations'}];
this.markerTypes= test;
console.log(this.markerTypes[1].desc);
this.markerForm.controls['markerType'].setValue( this.markerTypes[1], {onlySelf: true});