可以使用函数返回ng-select中的选项
。可以将变量作为$scope进行访问。播放器,$scope。播放器1,$scope。您已经定义了player2。确保将这三个变量初始化为默认值(否则未定义,并在下拉列表中显示为空白选项)
angular.module('myApp', [])
.controller('Ctrl', function($scope) {
$scope.widths = [{ width: 300 }, { width: 500 }, { width: 400 }];
$scope.getTopOptions = function () {
var ret = [];
if (!$scope.player2) {
return $scope.widths;
}
angular.forEach($scope.widths, function (width) {
if (width.width <= $scope.player2.width) {
ret.push(width);
}
});
return ret;
};
$scope.getBottomOptions = function(){
var ret = [];
if(!$scope.player2){
return $scope.widths;
}
angular.forEach($scope.widths, function (width) {
if (width.width > $scope.player2.width) {
ret.push(width);
}
});
return ret;
}
});
<html ng-app="myApp">
<head>
<title></title>
</head>
<body>
<div ng-controller="Ctrl">
<select ng-model="player" ng-options="w.width for w in getTopOptions() track by w.width" id="top"></select>
<select ng-model="player2" ng-options="w.width for w in widths track by w.width" id="sides"></select>
<select ng-model="player3" ng-options="w.width for w in getBottomOptions() track by w.width" id="bottom"></select>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
</body>
</html>