【发布时间】:2017-11-28 16:23:56
【问题描述】:
我无法将选定的值返回给模型,但能够将模型值绑定为选择控件中的选定项。
查看:
<div data-ng-repeat="BI in BulkInvoice">
<select class="input-sm form-control input-s-sm inline" ng-disabled="!edit" data-ng-model="BI.DefaultCostType">
<option value="">Select</option>
<option ng-selected="BI.DefaultCostType == item.ID"
ng-repeat="item in costTypes"
ng-value="item.ID">
{{item.Name}}
</option>
</select>
</div>
控制器:
$scope.BulkInvoice = [{
DefaultCostType : 4
}];
使用上面的代码,选择控件可以根据 BulkInvoice 中的 id 设置选择的项目。但是当用户在保存点击更改选项时更改选项不会发送回模型。请帮忙。
输出html:
<select class="input-sm form-control input-s-sm inline" ng-disabled="!edit">
<option value="">Select</option>
<!-- ngRepeat: item in costTypes --><option ng-selected="BI.DefaultCostType == item.ID" ng-repeat="item in costTypes" ng-value="item.ID" ng-model="BI.DefaultCostType" class="ng-pristine ng-untouched ng-valid ng-binding ng-scope ng-not-empty" value="1">
Claim Cost
</option><!-- end ngRepeat: item in costTypes --><option ng-selected="BI.DefaultCostType == item.ID" ng-repeat="item in costTypes" ng-value="item.ID" ng-model="BI.DefaultCostType" class="ng-pristine ng-untouched ng-valid ng-binding ng-scope ng-not-empty" value="3">
Expense - A&O
</option><!-- end ngRepeat: item in costTypes --><option ng-selected="BI.DefaultCostType == item.ID" ng-repeat="item in costTypes" ng-value="item.ID" ng-model="BI.DefaultCostType" class="ng-pristine ng-untouched ng-valid ng-binding ng-scope ng-not-empty" value="4">
Expense - D&CC
</option><!-- end ngRepeat: item in costTypes --><option ng-selected="BI.DefaultCostType == item.ID" ng-repeat="item in costTypes" ng-value="item.ID" ng-model="BI.DefaultCostType" class="ng-pristine ng-untouched ng-valid ng-binding ng-scope ng-not-empty" value="2" selected="selected">
Unspecified Cost Type
</option><!-- end ngRepeat: item in costTypes -->
</select>
【问题讨论】:
-
可以显示生成的html吗?
-
添加了输出html
标签: angularjs