【发布时间】:2020-05-09 10:37:51
【问题描述】:
我正在尝试实现 selectAll() 和 deselectAll() 但它显示错误:
我正在使用模板驱动的表单。这是我的代码:
<mat-selection-list name="role" *ngIf='userActions === AssignmentTypesForProductivityAppsEnum.UserRole'
[(ngModel)]="assignProductivityApplication.roleIds" #UserRoles="ngModel" multiple required>
<mat-list-option #allSelected (click)="selectAll(allSelected.selected)" [value]="0"
checkboxPosition="before">All</mat-list-option>
<mat-list-option *ngFor="let role of userRoles | searchFilter : searchTerm : 'role'; let i=index"
checkboxPosition="before" [value]='role.guId'>
{{role.role}}
</mat-list-option>
</mat-selection-list>
在ts文件中:
@ViewChild('allSelected', {static: true}) private allSelected: MatSelectionList;
selectAll(checkAll) {
if (checkAll) {
this.assignProductivityApplication.UserRoles = [];
this.assignProductivityApplication.UserRoles.push(... this.userRoles.map(item => item.guId));
this.allSelected.selectAll();
}
}
【问题讨论】:
标签: javascript angular typescript angular-material angular8