ng-multiselect-dropdown onDeSelectAll()不起作用

时间:2019-04-08 11:42:56

标签: angular

我在我的角度代码中使用ng-multiselect下拉列表。虽然所有onSelect,onSelectAll,onDeSelect方法都可以正常工作,但onDeselctAll方法不会收到取消选择的项目数组。我检查了官方网站,但没有用:https://www.npmjs.com/package/ng-multiselect-dropdown。 知道我可能会出错吗? PFB代码段:

.html文件

<ng-multiselect-dropdown *ngIf="filteredSids.length > 0"
                                             [data]="filteredSids"
                                             [disabled]="false"
                                             [(ngModel)]="selectedSids"
                                             (onSelect)="selectedSIDs($event); onItemSelect($event)"
                                             (onSelectAll)="onSelectAll($event)"
                                             (onDeSelect)="onItemDeSelect($event)"
                                             (onDeSelectAll)="onDeSelectAll($event)"
                                             [settings]="dropdownSettings"
                                             formControlName="sidControl">
                    </ng-multiselect-dropdown>

.ts文件

onSelectAll(selectedSIDList: Array<string>): void {
        selectedSIDList.forEach(sid => {
            this.selectedSIDs(sid);
            this.onItemSelect(sid);
        });
    }

    onItemDeSelect(deselectedSID: any): void {
        this.selectedSIDList = this.selectedSIDList.filter(s => s != deselectedSID);

        this.selectedSIDList.forEach(sid => {
            this.onItemSelect(sid);
        });
    }

    onDeSelectAll(items: any){
        console.log(items); // items is an empty array
    }

1 个答案:

答案 0 :(得分:0)

根据source code,接收空数组是正确的行为:

this.selectedItems = [];
this.onDeSelectAll.emit(this.emittedValue(this.selectedItems));

如果要跟踪被取消选择的项目,则需要找到其他方法。