AngularJS Select默认值?

AngularJS Select绑定的是对象:

$scope.cars = {
car01 : {brand : "Ford", model : "Mustang", color : "red"},
car02 : {brand : "Fiat", model : "500", color : "white"},
car03 : {brand : "Volvo", model : "XC90", color : "black"}
};
<select ng-model="selectedCar" ng-options="y.brand for (x, y) in cars"></select>

现在想给select一个默认值怎么设置呢?

阅读 3.6k
2 个回答
<select ng-model="selectedCar" ng-options="y.brand for (x, y) in cars>
</select>
$scope.selectedCar = $scope.cars.car01;

这样就是默认选中第一项

<option>--please select--</option>

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进