I have the following problem, I hope you can help me:
I have a form in my HTML template:
<form #formulario="ngForm" autocomplete="off">
<div>
<label for="periodo">Periodo</label>
<select id="periodo" #periodo ngModel required name="periodo">
<option *ngFor="let periodo of periodos" [value]="periodo.id">{{periodo.fecha_inicio}}</option>
</select>
</div>
</form>
And I would like to know how I can define a default option in my select . I have already tried adding the attribute [selected]="defaultValue" but I do not get the expected result.
Any suggestions are welcome ...
SOLUTION
Ok, I could solve it. I'll leave my answer in case it helps someone:
I defined in my file .ts a variable with the value that I hope to set by default:
defaultValue = val;
and in my template HTML
<form #formulario="ngForm" autocomplete="off">
<div>
<label for="periodo">Periodo</label>
<select id="periodo" #periodo ngModel required name="periodo">
<option *ngFor="let periodo of periodos" [value]="periodo.id" [selected]="default == paralelo.descripcion">{{periodo.fecha_inicio}}</option>
</select>
</div>
</form>