这是您正在寻找的 plunker 示例。选择列表会根据您的其他选择自动更改。
http://plnkr.co/edit/yFrYQ1ql9a1x9jd9yGv0
您可以概括 n 个列表,然后遍历所有列表以进行任何更改。
<!DOCTYPE html>
<html ng-app="angularjs-starter">
<head lang="en">
<meta charset="utf-8">
<title>Custom Plunker</title>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.0.3/angular.min.js"></script>
<script src="app.js"></script>
</head>
<body ng-controller="MainCtrl">
<h1>Hello {{name}}</h1>
<p>
First List: <select ng-change="onChange()" ng-options='person.name for person in first.list | filter:{selected: false}' ng-model='first.option'><option value="">-- pick one --</option> </select> {{first.option.name}}
</p>
<p>
Second List: <select ng-change="onChange()" ng-options='person.name for person in second.list | filter:{selected: false}' ng-model='second.option'><option value="">-- pick one --</option></select> {{second.option.name}}
</p>
<p>
Third List: <select ng-change="onChange()" ng-options='person.name for person in third.list | filter:{selected: false}' ng-model='third.option'><option value="">-- pick one --</option></select> {{third.option.name}}
</p>
</select>
</body>
</html>
角码
var app = angular.module('angularjs-starter', []);
app.controller('MainCtrl', function($scope) {
$scope.name = 'World';
$scope.masterlist =
[ {name: 'John', selected: false}, {name: 'Bill', selected: false},
{name: 'Smith', selected: false}, {name: 'Alex', selected: false},
{name: 'Martin', selected: false}, {name: 'James', selectes: false}];
$scope.first = {list: angular.copy($scope.masterlist), option: null};
$scope.second = {list: angular.copy($scope.masterlist), option: null};
$scope.third = {list: angular.copy($scope.masterlist), option: null};
$scope.onChange = function(){
$scope.enableAllOptions($scope.first.list);
$scope.enableAllOptions($scope.second.list);
$scope.enableAllOptions($scope.third.list);
$scope.disableOptions($scope.first.list, $scope.second.list, $scope.second.option);
$scope.disableOptions($scope.first.list, $scope.third.list, $scope.third.option);
$scope.disableOptions($scope.second.list, $scope.first.list, $scope.first.option);
$scope.disableOptions($scope.second.list, $scope.third.list, $scope.third.option);
$scope.disableOptions($scope.third.list, $scope.first.list, $scope.first.option);
$scope.disableOptions($scope.third.list, $scope.second.list, $scope.second.option);
};
//Enable all options by default.
$scope.enableAllOptions = function(arr)
{
for(var i=0;i<arr.length;i++)
{
arr[i].selected = false;
}
};
//Function that takes the destinationArr , Source Arry , and Source selected item
$scope.disableOptions = function(destArr, srcArr, srcItem)
{
if(srcItem !== null)
{
var index = srcArr.indexOf(srcItem);
if(index >=0) destArr[index].selected = true;
}
};
});