【发布时间】:2015-01-27 17:24:26
【问题描述】:
我的问题与这个问题非常相似:AngularJS - Value attribute on an input text box is ignored when there is a ng-model used?
考虑到这个答案:https://stackoverflow.com/a/20522955/1598891
我想知道是否有办法对<select> 进行同样的处理?
如果将 ng-model 设置为 <input type="text">,则输入的值将重置为 null(因为 Angular)
下拉列表也有类似的行为。如果您在 <select> 中设置了“选定选项”,如果您还具有 ng-model 属性,它将被忽略。
我是 Angular 新手,但我发现这真的很烦人。
由于我正在使用 ASP MVC,如果我这样做,MVC 已经定义了所有值:
@Html.DropDownListFor(model => model.MyModel,
new SelectList(/*...*/),
"Select an options",
new { @class = "form-control",
ng_model = "MyModelProperty"})
我知道我可以这样做:
ng_model = @String.Format("myModel = {0}", Model.MyModelProperty)
但是重复这些信息会有点烦人,因为 MVC 应该已经正确地做到了。
【问题讨论】:
标签: javascript asp.net asp.net-mvc angularjs