After conducting some research, I was surprised to find that the process is not as straightforward as I had expected.
I have come across various methods using ngModel, such as Bind and fetch dropdown list value in typescript and Angular2, among others. However, I am looking for a way to easily bind my selected option to my formControlName variable.
This is what I have attempted:
.HTML
<form id="myForm" name="father" [formGroup]="fatherForm" (ngSubmit)="createFather()">
<div class="row">
<select formControlName="pref" id="f">
<option value=null disabled selected>Prefijo</option>
<option *ngFor="let item of prefs" [ngValue]="hello">{{item.name}}</option>
</select>
</div>
</form>
.TS
fatherForm: FormGroup;
this.fatherForm = this.formBuilder.group({
pref: ['AA']
});
this.prefs=[
{name: "AA"},
{name: "BB"}
];
The default value works. However, when I choose 'BB', the default value remains selected. The same issue occurs when the default value is set as an empty string.
This method is recommended by Harry-ninh in Bind Select List with FormBuilder Angular 2
What could be the mistake in my implementation?
Note: there are other form inputs present, but they have been omitted for simplicity's sake.
EDIT
I also attempted to replicate the exact same example in this Plunkr, but it did not work either. http://plnkr.co/edit/Rf9QSSEuCepsqpFc3isB?p=preview Upon submitting the form, it shows that the value has not been altered.