【发布时间】:2015-07-14 22:18:13
【问题描述】:
问题:
我的页面中有一个 SELECT 元素,用 ng-repeat 填充。它还有一个ng-model,它有一个默认值。
当我更改值时,ng-model 会适应,没关系。但是下拉列表在启动时显示一个空槽,它应该选择具有默认值的项目。
代码
<div ng-app ng-controller="myCtrl">
<select class="form-control" ng-change="unitChanged()" ng-model="data.unit">
<option ng-repeat="item in units" ng-value="item.id">{{item.label}}</option>
</select>
</div>
用JS:
function myCtrl ($scope) {
$scope.units = [
{'id': 10, 'label': 'test1'},
{'id': 27, 'label': 'test2'},
{'id': 39, 'label': 'test3'},
]
$scope.data = {
'id': 1,
'unit': 27
}
};
【问题讨论】:
标签: javascript jquery angularjs angular-ngmodel