我想在我的选择中预先选择一个值但没有任何内容,为什么会这样?
angular.module('selectExample', [])
.controller('ExampleController', ['$scope', function($scope) {
$scope.cardSelect = [
{name:'black', shade:'dark'},
{name:'white', shade:'light'},
{name:'red', shade:'dark'},
{name:'blue', shade:'dark'},
{name:'yellow', shade:'light'}
];
$scope.card = $scope.cardSelect[2]; // red
}]);
答案 0 :(得分:3)
使用ng-options
代替ng-repeat
<select data-ng-model="card" ng-options="card.name for card in cardSelect">
这是plunker