My issue involves a select
element containing a form control name. When I utilize
<option value = "" selected disabled> Select </option>
with the reactForms
library, the placeholder
is not being displayed until the user makes a selection.
Here's the code snippet in HTML:
<form [formGroup]="formEndereco">
<select formControlName="parentesco" id="parentesco" class="form-control input-lg" matInput>
<option value="" selected="selected">Select</option>
<option *ngFor="let itemParentesco of parentescos" [ngValue]="itemParentesco.name">
{{itemParentesco.name }}</option>
</select>
</form>
TypeScript section:
gerarFormGroupEndereco() {
this.formEndereco = this.formBuilder.group({
parentesco: [],
estado: [[Validators.required]]
});
}
Issues arise when using formControlName
within the select element:
https://i.sstatic.net/aKHP4.png
Removing formControlName
from select results in:
https://i.sstatic.net/3reLV.png