-3
在documentation中有一个使用ng-select
的示例,其中包含下面的片段。如何使ng-select的选项列表以当前“selected”属性呈现
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<script>
angular.module('selectExample', [])
.controller('ExampleController', ['$scope', function($scope) {
$scope.colors = [
{name:'black', shade:'dark'},
{name:'white', shade:'light'},
{name:'red', shade:'dark'},
{name:'blue', shade:'dark'},
{name:'yellow', shade:'light'}
];
$scope.myColor = $scope.colors[2]; // red
}]);
</script>
<div ng-app="selectExample" ng-controller="ExampleController">
<select ng-model="myColor" ng-options="color.name for color in colors"></select>
<p>Selected: {{myColor}}</p>
</div>
但是,当你选择不同的颜色比默认的(红色)的HTML仍然呈现与
<option value="2" selected="selected">red</option>
这是错的?如果是这样,我该如何解决它?