当我使用此code.selected值显示为empty.i时,请将第一个值选为一个。
dtype
当我使用ng-model时,默认值选为empty.otherwise ok。
答案 0 :(得分:2)
在控制器中尝试init sRoom
模型
$scope.sRoom = 1;
还可以更好地使用ng-options
代替option
代码中的重复select
。
<强> 演示 强>
var app = angular.module('anApp', []);
app.controller('aCtrl', function($scope) {
$scope.sRoom = 1;
$scope.chooses = [{"key":"one","value":1},{"key":"Two","value":2},{"key":"Three","value":3}];
})
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="anApp" ng-controller="aCtrl">
<select ng-change="RoomSelect()" ng-model="sRoom" ng-options="k.value as k.key for k in chooses">
</select>
</div>
答案 1 :(得分:0)
试试这个
<select class="form-control" ng-init="sRoom=1" name="cityID" id="Select1" ng-change="RoomSelect()" ng-model="sRoom">
<option value="1" selected="selected">One</option>
<option value="2">Two</option>
<option value="3">Three</option>
<option value="4">Four</option>
</select>
答案 2 :(得分:0)
您也可以使用ng-init
<select class="form-control" ng-init="sRoom=1" name="cityID" id="Select1" ng-change="RoomSelect()"