答案 0 :(得分:0)
使用正确的ngOptions
语法可以解决问题:
(function(angular) {
angular.module('m', [])
.run(function($rootScope) {
$rootScope.nums = ["Zero", "One", "Two"];
$rootScope.x = {
val: "One"
};
});
})(window.angular);
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.4.3/angular.min.js"></script>
<div ng-app="m">
<select ng-model="x.val" ng-options="num as num for num in nums"></select><br />
selected value: {{ x.val }}
</div>
答案 1 :(得分:0)
这是另一种解决方案。
(function(angular) {
angular.module('m', [])
.run(function($rootScope) {
$rootScope.nums = ["Zero", "One", "Two"];
$rootScope.x = $rootScope.nums[1]; // Index position of One
});
})(window.angular);
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.4.3/angular.min.js"></script>
<div ng-app="m">
<select ng-model="x" ng-options="num as num for num in nums"></select><br />
selected value: {{ x }}
</div>