我用Slectall和Deselect all选项创建了Multi select下拉列表。 在这里,我有所有复选框,可以选择全部并取消选择所有复选框,但是它仅在工作一次之后才起作用,有人可以在下面的代码中帮助我。
<md-select ng-model="selectedUser" multiple="" ng-model-options="{trackBy: '$value'}">
<md-optgroup >
<md-option ng-value="" ng-click="doSelectedUser()">all</md-option>
<md-option ng-value="user" ng-repeat="user in newusers">{{ user}}</md-option>
</md-optgroup>
</md-select>
下面是我的控制器
var myApp = angular.module('sandbox', ['ngMaterial']);
myApp.controller('myCtrl', function($scope) {
$scope.selectedUser =[];
$scope.newusers = ['A','B','c']
$scope.doSelectedUser = function () {
if($scope.selectedUser.length > 0)
{
$scope.selectedUser = [];
} else {
$scope.selectedUser = $scope.newusers; }
}
});
答案 0 :(得分:0)
您必须与此
<md-select ng-model="selectedUser" multiple="" ng-model-options="{trackBy:
'$value'}">
<md-optgroup>
<md-button layout-fill ng-click="doSelectedUser()">
{{(selectedUser.length == newusers.length)?'Deselect All':'Select All'}}
</md-button>
</md-checkbox>
<md-option ng-value="user" ng-repeat="user in newusers" >{{ user}}</md-option>
</md-optgroup>
</md-select>
和
$scope.selectedUser = [];
$scope.newusers = ['A', 'B', 'c']
$scope.doSelectedUser = function () {
if ($scope.selectedUser.length == $scope.newusers.length) {
$scope.selectedUser = [];
} else {
$scope.selectedUser = $scope.newusers;
}
}