【发布时间】:2016-12-08 17:22:00
【问题描述】:
如何在我的 Angular 2 应用程序中通过分组实现多选下拉?我需要像这个问题How can implement grouping in ng-select of Angular2? 中链接的图像一样的下拉菜单。请帮帮我.....从最近几天开始我就一直坚持这一点
我已经尝试过像下面这样的 angular-ngselect 但它的:
组件 Html:
<form [formGroup]="form" class="selector-form">
<div class="marTop20">
<ng-select [options]="options1"
[multiple]="multiple1"
placeholder="Select multiple"
formControlName="selectMultiple"
(opened)="onMultipleOpened()"
(closed)="onMultipleClosed()"
(selected)="onMultipleSelected($event)"
(deselected)="onMultipleDeselected($event)">
</ng-select>
</div>
</form>
ts文件中的组件代码:
export class FilterClientSelectorComponent implements OnInit {
form: FormGroup;
multiple1: boolean = true;
options1: Array<any> = [];
selection: Array<string>;
@ViewChild('preMultiple') preMultiple;
logMultipleString: string = '';
constructor() {
let numOptions = 100;
let opts = new Array(numOptions);
for (let i = 0; i < numOptions; i++) {
opts[i] = {
value: i.toString(),
label: i.toString(),
groupname:'a'
};
}
this.options1 = opts.slice(0);
}
ngOnInit() {
this.form = new FormGroup({});
this.form.addControl('selectMultiple', new FormControl(''));
}
private scrollToBottom(elem) {
elem.scrollTop = elem.scrollHeight;
}
}
它给了我多个选择下拉列表,但没有分组:
电流输出:
所需输出:
【问题讨论】:
-
@silentsod 现在检查我的代码伙伴