Hi I am having a reactive form. I am having a select box in my component html. I want my select box to choose one of the options as default selected . Any idea what should i do ?
also i am using angular 5
so here is my form
this.formGroup = this.fb.group({
inventories: this.fb.array([]),
flightRates: this.fb.array([]),
settings: this.fb.array([]),
tagonSettings: this.fb.array([])
});
my form group uses form arrays. In the tagonSettings form array i am pushing some form group
this.globalTagonSettingsArray.push(
new FormGroup({
id : new FormControl( globalTagonSetting.id ),
tagonText: new FormControl(globalTagonSetting.tagonText, [Validators.required] ),
tagonType: new FormControl(globalTagonSetting.tagonType, [Validators.required] )
}
)
);
in my html code below i have a select box . i want one of the options to be default selected based on the value of the formcontrol "tagonText" . any idea what should i do ?
<div formArrayName="tagonSettings">
<div class="row" *ngFor="let tagonSettingFormGroup of globalTagonSettingsArray.controls; let i = index">
<div [formGroup]="tagonSettingFormGroup" >
<div class="input-group">
<input formControlName="tagonText">
<select [formControlName]="tagonType">
<option *ngFor="let tagon of tagOns" [value]="tagon.code"> {{ tagon.code }} </option>
</select>
</div>
</div>
</div>
</div>