angular.js - AngularJS Select默认值?
本文介绍了angular.js - 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一个默认值怎么设置呢?
解决方案
<select ng-model="selectedCar" ng-options="y.brand for (x, y) in cars>
</select>
$scope.selectedCar = $scope.cars.car01;
这样就是默认选中第一项
这篇关于angular.js - AngularJS Select默认值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文