我在我的 Angular 6 项目中使用 ng-select ( https://github.com/ng-select/ng-select ),并且我最近升级到了 Bootstrap 4。
从那时起,我注意到我用于禁用元素的自定义逻辑现在不再起作用了。
<ng-select
style="width: 500px;"
[multiple]="true"
[(items)]="usersList"
[closeOnSelect]="false"
[isOpen]="toggleUsersPicker"
[(ngModel)]="selectedPeople"
[virtualScroll]="true"
(add)="onAdd($event)"
(remove)="onRemove($event)"
(clear)="onClear()"
(change)="onChange()"
placeholder="Select people"
bindLabel="label">
<ng-template ng-header-tmp>
<button (click)="selectAll()" class="btn btn-light margin10">Select all</button>
<button (click)="unselectAll()" class="btn btn-light margin10">Unselect all</button>
</ng-template>
...
</ng-select>
然后我的逻辑是禁用元素。
selectAll() {
this.selectedPeople = [];
this.selectedPeople.push({label: 'All'});
this.selectedNumber = this.usersList.length;
const usersListTmp = this.usersList.slice();
for (const u of usersListTmp) {
u.disabled = true;
}
this.usersList = usersListTmp;
this.onChange();
}
目标变量的定义是这样的:
selectedPeople: NgOption[] = [];
usersList: NgOption[] = [];
有同样问题的人吗?