我已经检查了文档和演示,但是天哪!我还没有找到任何实现多选选项的参考,比如使用angular-material的select 2。有没有人能告诉我怎么做?
发布于 2015-09-08 13:35:07
Splaktar的答案是正确的:只需在md-select中添加多个即可。
工作解决方案的代码:http://codepen.io/ansgar-john/pen/RWPVEO?editors=101
HTML
<div>
<md-input-container>
<md-select multiple ng-model="ctrl.likedAnimals" placeholder="please select">
<md-option ng-repeat="a in ctrl.animals" value="{{a}}">{{a}}</md-option>
</md-select>
</md-input-container>
</div>JS
(function () {
'use strict';
angular
.module('MyApp')
.controller('AppCtrl', function($scope) {
this.likedAnimals = ["mouse", "dog"];
this.animals = ["mouse", "dog", "cat", "bird"];
});
})();基于堆栈溢出的代码答案:How am I supposed to implement multiple select option in angular-material?
发布于 2015-08-13 18:16:06
查看chips
您也可以应用您自己的自定义模板。
发布于 2015-10-01 22:49:39
我使用下面的代码来允许我使用ng-repeat和一些md-select,它们是多个的,有些不是(从Angular 1.4.7开始):
index.html
<md-input-container ng-repeat="item in items track by $index">
<label>{{item.title}}</label>
<div ng-include="item.multiselect == 'true' ? 'm_selectfragment.html' : 's_selectfragment.html'"></div>
</md-input-container>Javascript
$scope.items =
[{title: 'funny',
selected: '',
names: [
{name: 'some name'},
{name: 'other name'},
{name: 'more?'},
{name: 'say wha???'}
],
multiselect: "false"
},
{title: 'serious',
selected: '',
names: [
{name: 'Obama'},
{name: 'Trump'},
{name: 'Hillary'},
{name: 'Putin'}
],
multiselect: "true"
}];m_selectfragment.html
<md-select name="item.title" ng-model="item.selected" multiple="true">
<md-option ng-repeat="name in item.names" value="{{name.name}}">{{name.name}}
</md-option>
s_selectfragment.html
<md-select name="item.title" ng-model="item.selected">
<md-option ng-repeat="name in item.names" value="{{name.name}}">{{name.name}}
</md-option>
https://stackoverflow.com/questions/28655946
复制相似问题