I have a FormGroup with 2 FormControls "name" and "type". Type is a select html input with options generated with a ngFor loop. So when I edit my Element the Component with the FormGroup shows up, it loads the Element I want to edit and automatically fills in the Name of the Element in the name input field. What I trying to do is the same with the type field.
mycomponent.html
<form [formGroup]="myForm" (ngSubmit)="onMyFunktion()">
<div class = "form-group">
<label for="name">Name</label>
<input formControlName="name" type="text" id="name" class="form-control" required >
</div>
<div class="form-group">
<label for="type">Type</label>
<select formControlName="type" id="type" class="form-control" required >
<option *ngFor="let Type of types" value="Type.Id">{{Type.Name}}</option>
</select>
</div>
<button type="submit" [disabled]="!MyForm.valid" class ="btn btn-primary">save</button>
<button type="button" (click)="onBack()" class ="btn btn-success">Back</button>
</form>
mycomponent.ts
ngOnInit()
{
this.MyForm = new FormGroup
({
name: new FormControl(this.myElement.Name),
type: new FormControl() // myElement only has its Name and the Id of the type not the type name
})
}