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

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -