为什么在angularjs 1.4.x中,默认选择禁用选项不起作用,但在angularjs 1.5.x中运行良好?
例如,以下代码适用于angularjs 1.5.5(默认选择白色,禁用):
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Example - example-select-production</title>
<script src="//code.angularjs.org/1.5.5/angular.min.js"></script>
</head>
<body ng-app="selectExample">
<script>
angular.module('selectExample', [])
.controller('ExampleController', ['$scope', function($scope) {
$scope.myColor = {name:'white', shade:'light'}; // red
$scope.colors = [
{name:'black', shade:'dark'},
{name:'white', shade:'light', notAnOption: true},
{name:'red', shade:'dark'},
{name:'blue', shade:'dark', notAnOption: true},
{name:'yellow', shade:'light'}
];
}]);
</script>
<div ng-controller="ExampleController">
<label>Color filtered by shade, with some disabled:
<select ng-model="myColor.name" validate-on="dirty" required-message="'This field is required'" ng-disabled="false" ng-required = "true"
ng-options="color.name as color.name group by color.shade disable when color.notAnOption for color in colors | filter:{'shade':'light'}:true">
</select>
</label><br/>
<hr/>
Currently selected: {{ {selected_color:myColor} }}
<div style="border:solid 1px black; height:20px"
ng-style="{'background-color':myColor.name}">
</div>
</div>
</body>
</html>
但是,在上例中,将版本更改为script
标记中的1.4.7,默认情况下不会选择白色
请参阅此plunkr:https://plnkr.co/edit/UAOFj5MEow3xEWH0ZLyz?p=preview
如何让1.4.x中的行为在1.5.x中正常工作?