angular - "selected" tag on option doesn't work when select has formControlName -
<div class="form-inline"> <label class="text-color">lokalizacja:</label> <select class="form-control dropdown" formcontrolname="localization"> <option value="gdańsk" selected>gdańsk</option> <option value="rzeszów">rzeszów</option> <option value="wrocław">wrocław</option> </select> </div> don't know happened in case there no selected option , have choose list. when delete formcontrolname="localization select, gdańsk selected @ start.
lokalization control looks localizationctrl = new formcontrol("", validators.required);
there no difference when replace on: localizationctrl = new formcontrol(""); of course next step add control offerform doing:
... localization: this.localizationctrl ... but please don't try problem here because have 7 other validators inside offerform , of them work fine.
assign default value during form model initialization.
`localizationctrl = new formcontrol("gdańsk", validators.required);` or if value coming server, use formcontrol's updatevalue method.
localizationctrl.updatevalue('gdańsk'); see here: https://scotch.io/tutorials/using-angular-2s-model-driven-forms-with-formgroup-and-formcontrol , https://scotch.io/tutorials/how-to-deal-with-different-form-controls-in-angular-2
Comments
Post a Comment