angular - Ng-Select 不使用 Bootstrap 4 禁用元素
问题描述
我在我的 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[] = [];
有同样问题的人吗?
解决方案
确保您引用了 Bootstrap CSS 和以下 JS 库:必须首先出现 jQuery,然后是 Popper.js,然后是 Bootstrap JS。
Bootstrap 4 中的下拉菜单需要Popper.js来显示和定位。
推荐阅读
- typescript - NestJS 和无服务器 - 处理程序“处理程序”不是函数
- oracle - 用于 kibana 的 oracle jdbc 驱动程序配置
- javascript - 如何确保 shinyjs::runjs 在 DOM 更新后运行?
- javascript - Chart.js:如何获得由其他线的总和创建的线?
- amazon-web-services - Route53:将多个域名解析到单个私有托管区域
- python - 执行 pandas 操作以填充缺失的月份数据时出错
- javascript - 日期最小值和最大值,onchange 事件侦听器迄今为止无法正常工作
- javascript - loadSVGFromString 没有将标签识别为对象
- javascript - 为什么 @change 或 @input 可以与自定义 v-model 组件一起使用?
- reactjs - 我需要访问对象消息中的数据:“{'data':{'status':'active'}}”。stringfy 访问时抛出错误