1tosslePerOne(all){
2 if (this.allSelected.selected) {
3 this.allSelected.deselect();
4 return false;
5}
6 if(this.searchUserForm.controls.userType.value.length==this.userTypeFilters.length)
7 this.allSelected.select();
8
9}
10 toggleAllSelection() {
11 if (this.allSelected.selected) {
12 this.searchUserForm.controls.userType
13 .patchValue([...this.userTypeFilters.map(item => item.key), 0]);
14 } else {
15 this.searchUserForm.controls.userType.patchValue([]);
16 }
17 }
18
19------------------- HTML-----------
20
21<form [formGroup]="searchUserForm" fxFlex fxLayout="column" autocomplete="off" style="margin: 30px">
22 <mat-select placeholder="User Type" formControlName="userType" multiple>
23 <mat-option *ngFor="let filters of userTypeFilters" [value]="filters.key" (click)="tosslePerOne(allSelected.viewValue)">
24 {{filters.value}}
25 </mat-option>
26 <mat-option #allSelected (click)="toggleAllSelection()" [value]="0">All</mat-option>
27 </mat-select>
28</form>
29