是否有一种方法可以使用角色素材的Md-select来显示检查了多少个复选框,而不是显示所有选定的值。例如,如果我有4种选择意大利辣香肠,奶酪,香肠和蔬菜,我选择其中三种。我将如何显示" 3 Selected",而不是写出整个选择。
答案 0 :(得分:3)
标记
<div ng-controller="SelectOptGroupController as vm" class="md-padding" ng-cloak="" ng-app="MyApp">
<div>
<h1 class="md-title">Pick your pizza toppings</h1>
<md-input-container md-no-float>
<label>Toppings</label>
<md-select ng-model="vm.selectedToppings" multiple="" md-selected-text="vm.text" md-offset="0 30">
<md-option ng-value="topping.name" ng-repeat="topping in vm.toppings">{{topping.name}}</md-option>
</md-select>
</md-input-container>
</div>
</div>
JS
angular.module('MyApp',['ngMaterial'])
.controller('SelectOptGroupController', function($scope) {
var vm = this;
vm.toppings = [
{ name: 'Pepperoni' },
{ name: 'Cheese' },
{ name: 'Sausage' },
{ name: 'Veggies' }
];
vm.selectedToppings = [];
$scope.$watch("vm.selectedToppings", function () {
vm.text = vm.selectedToppings.length + " Toppings selected";
})
});