I'm trying to create a "multi-level" mat-select and I'd like to use both checkboxes and radio buttons.
An example of how it could be used to set properties for a car (assuming a radio can only be Digital or FM):
- [v] Stero
- [v] Radio
- ---(o) Digital
- ---( ) FM
- [ ] Child seats
- [ ] Rear camera
The radio buttons should only appear if the "parent" option is checked, in this case Radio.
<mat-form-field>
<mat-select [(value)]="viewValue" #multipleSelect (openedChange)="onMultipleChange($event, multipleSelect.selected)" multiple>
<ng-container *ngFor="let property of carProperties">
<!-- If the property does not have any subProperties, display the property. Else display the nested options (subProperties) -->
<mat-option *ngIf="!property.subProperties; else nestedOption" [value]="property.value">
{{property.value}}
</mat-option>
<ng-template #nestedOption>
<mat-checkbox #parentOption>
{{property.value}}
</mat-checkbox>
<ng-container *ngIf="parentOption.checked">
<ng-template #radioOptions>
<mat-radio-group (change)="radioChange($event)"> <!-- Not sure what the ngModel should be here -->
<mat-radio-button *ngFor="let subProperty of property.subProperties" [value]="subProperty.value">
{{subProperty.value}}
</mat-radio-button>
</mat-radio-group>
</ng-template>
</ng-container>
</ng-template>
</ng-container>
</mat-select>
</mat-form-field>
I've created a solution but as I select a radio button I'll get this exception:
"Value must be an array in multiple-selection mode at getMatSelectNonArrayValueError (select.es5.js:116) at MatSelect.push.."
I assume this is because the mat-select looks for changes within its structure, where the radio buttons are placed. How can I structure the mat components to get the desired behavior?