I am looking to implement a mat-option filter that should select all options by default. To achieve this, I initially used
.setValue([1,2,3,4,5,6,7,8])
However, I now need the array to be passed dynamically from an API service.
So, I modified it as follows:
this.listApiService.getListOfEventTypes().subscribe(data => {
(data as Array<any>).forEach(type => {
this.allSelectedEventTypes.push(type.Id);
});
});
.setValue(this.allSelectedEventTypes);
Even though this approach returns the same array, the filter does not select the default options as expected.
Here is the output when printed in the console:
Hardcoded array:
Array(8) [ 1, 2, 3, 4, 5, 6, 7, 8 ]
Dynamically returned array:
Array []
and when expanded:
[]
0: 1
1: 2
2: 3
3: 4
4: 5
5: 6
6: 7
7: 8
length: 8
However, despite this, selecting all default multiple selections in the mat option filter is not working as intended.