【问题标题】:"onDropDownClose" event is getting triggered all time even if I click any where else other than the drop down in ng-multiselect-dropdown即使我单击 ng-multiselect-dropdown 中的下拉列表以外的任何其他位置,“onDropDownClose”事件也会一直触发
【发布时间】:2021-02-20 02:02:00
【问题描述】:

我正在使用 ng-multiselect-dropdown,我必须根据所选列表加载数据。 因此,我使用“onDropDownClose”事件来获取所有选定的值并根据选定的多个值加载其他数据。

   <ng-multiselect-dropdown
   [placeholder]="'Select Project'"
   [settings]="dropdownSettings"
   [data]="projects"
   [required]='requiredField' 
   [(ngModel)]="selectedItems"
   name="projectName"
   [ngClass]='setClass()'
  #projectName="ngModel"
  (onSelect)="onItemSelect($event)"
  (onSelectAll)="onSelectAll($event)" 
  (onDropDownClose)="saveFunction($event)">

但是即使我总是在下拉菜单之外单击,关闭事件也会一直触发。 有什么替代方法吗?请帮忙。

【问题讨论】:

    标签: html angular angular-material dropdown multi-select


    【解决方案1】:

    这应该在他们的最后修复,但在那之前你可以使用这个技巧: 除了 (onDropDownClose),在 ng-multiselect-dropdown

    上监听点击事件
     // this act as a differentiator between other calls(bug) and an intended call
     (click)="dropDownSelect = true".
    

    在你的组件中,声明你的变量并像这样使用它:

    dropDownSelect = false;
    
    saveFunction($event) {
     if (this.dropDownSelect) {
            // close the opening to subsequent actions 
            this.dropDownSelect = false;
            // Perform action;
     };
    }
    

    【讨论】:

      猜你喜欢
      • 2020-12-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-30
      • 2021-01-21
      • 2018-02-24
      • 1970-01-01
      相关资源
      最近更新 更多