【发布时间】:2015-03-26 00:22:27
【问题描述】:
我有一个下拉菜单。我在 Option 上使用ng-repeat 绑定它的值。
我只想使用值字段设置选定的值。
这是我的代码。
<div ng-controller="myCtrl">
<select ng-model="selectedItemvalue">
<option value="">--Select --</option>
<option ng-repeat="sel in selectables" value="{{sel.value}}">{{sel.label}}</option>
</select>
<p>Selected Value is : {{selectedItemvalue}}</p>
</div>
JS
angular.module('myApp', [])
// controller here
.controller('myCtrl', function($scope) {
$scope.selectables = [
{ label: 'A', value: 1},
{ label:'B', value: 2},
{ label: 'C', value: 3}
];
// this is the model that's used for the data binding in the select directive
// the default selected item
//using value, i want to set the selected value
$scope.selectedItemvalue = "2";
})
如您所见,我只想通过设置值来设置选定的值。
【问题讨论】:
标签: javascript jquery angularjs