我使用 angular 的 Select2 组件作为多重选择器。我需要一个选项来通过单击按钮或复选框来选择所有元素。https://www.npmjs.com/package/ng-select2
我尝试在按下按钮时在数组 [(ngModel)] = "value" 中插入元素的所有 id,但它没有用
.HTML 代码
<ng-select2 [data]="exampleData"
[options]="options"
[width]="200"
[(ngModel)]="value"
(valueChanged)="onTagChanged($event)">
</ng-select2>
<button (click)='selectAll()'>Select all</button>
.TS 代码
ngOnInit() {
this.exampleData = [
{
id: '0',
text: 'Pau Cano Dominguez',
},
{
id: '2',
text: 'Miguel Ángel Vargas Gomez'
},
{ id: '3',
text: 'Pedro Medina Cruz'
},
{ id: '4',
text: 'Oriol Fuentes Nuñez'
},
{
id: '5',
text: 'Rayan Mora Sanchez'
}
];
this.options = {
width: '200',
multiple: true,
tags: false
};
}
selectAll() {
console.log('Select All Pushed');
this.value.push('0');
this.value.push('1');
this.value.push('2');
this.value.push('3');
this.value.push('4');
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句