【发布时间】:2019-05-30 23:55:03
【问题描述】:
我正在尝试创建一个“多级”垫选择,我想同时使用复选框和单选按钮。
如何使用它来设置汽车属性的示例(假设收音机只能是数字或 FM):
- [v] 立体
- [v] 收音机
- ---(o) 数字
- ---( ) 调频
- [ ] 儿童座椅
- [ ] 后置摄像头
如果在这种情况下检查“父”选项,则只能出现单选按钮。
<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>
我已经创建了一个解决方案,但是当我选择一个单选按钮时,我会得到这个异常:
"值必须是多选模式下的数组 在 getMatSelectNonArrayValueError (select.es5.js:116) 在 MatSelect.push..”
我认为这是因为 mat-select 在其结构中查找更改,即放置单选按钮的位置。如何构建 mat 组件以获得所需的行为?
【问题讨论】:
标签: angular typescript angular-material