My question is very similar to this one : AngularJS - Value attribute on an input text box is ignored when there is a ng-model used?
Considering that answer : https://stackoverflow.com/a/20522955/1598891
I would like to know if there's a way to do the same treatment for a <select>
?
If you set a ng-model
to an <input type="text">
, the value of the input is reset to null (because of Angular)
There's a similar behavior for drop down lists. If you set a "selected option" in a <select>
, it will be ignored if you also had the ng-model
attribute.
I'm new to angular, but I found this really annoying.
Since I'm working with ASP MVC, MVC already defines all the values if I do :
@Html.DropDownListFor(model => model.MyModel,
new SelectList(/*...*/),
"Select an options",
new { @class = "form-control",
ng_model = "MyModelProperty"})
I know that I could do something like :
ng_model = @String.Format("myModel = {0}", Model.MyModelProperty)
but it would be kind of annoying to repeat that information since MVC should already do it properly.