Checkbox 错误:材料表单字段,材料选择列表必须包含材料表单字段控件

Checkbox 错误:材料表单字段,材料选择列表必须包含材料表单字段控件,checkbox,angular7,form-control,Checkbox,Angular7,Form Control,我正在尝试添加复选框并附加到表单字段。我用的是angular 7。 我使用的是tags mat表单字段,因此我得到了一个错误 mat form字段必须包含MatFormFieldControl 我已经检查了我的组件代码,并确保FormControl存在。虽然不是很清楚,但添加了formControl“mat selection list” HTML代码 <mat-form-field> <mat-selection-list #preConditions placeho

我正在尝试添加复选框并附加到表单字段。我用的是angular 7。 我使用的是tags mat表单字段,因此我得到了一个错误

mat form字段必须包含MatFormFieldControl

我已经检查了我的组件代码,并确保FormControl存在。虽然不是很清楚,但添加了formControl“mat selection list”

HTML代码

<mat-form-field>
    <mat-selection-list #preConditions placeholder="PreExisting Conditions" [formControl]="preexistingControl">
        <mat-list-option *ngFor="let preExistingCond of preExistingCondList">
                        {{preExistingCond.value}}
        </mat-list-option>
    </mat-selection-list>
</mat-form-field>

我已检查formControl是否存在,并且ref id是否正确。

根据以下文档:

以下角材质组件设计用于在内部工作

<mat-form-field>
<input matNativeControl> & <textarea matNativeControl>
<select matNativeControl>
<mat-select>
<mat-chip-list>

<mat-selection-list> is not supported for now.

& 
目前不支持。

根据以下文件:

以下角材质组件设计用于在内部工作

<mat-form-field>
<input matNativeControl> & <textarea matNativeControl>
<select matNativeControl>
<mat-select>
<mat-chip-list>

<mat-selection-list> is not supported for now.

& 
目前不支持。

这可以通过一个小的变通方法来实现,这适用于任何不受支持的材料组件。您可以像这样将它们嵌套在mat form字段中

    <mat-form-field [formGroup]="formGroup" class="mat-form-field--no-underline">
        <!-- Important part, input with matInput -->
        <input matInput style="display: none!important">
        <mat-selection-list #preConditions [formControl]="preexistingControl" [(ngModel)]="controlAnswer.value">
            <mat-list-option *ngFor="let preExistingCond of preExistingCondList">
                {{preExistingCond.value}}
            </mat-list-option>
        </mat-selection-list>
     </mat-form-field>

如果样式不适用,可以使用ngdeep将其应用

可以通过一些小的变通方法来实现,这适用于任何不受支持的材质组件。您可以像这样将它们嵌套在mat form字段中

    <mat-form-field [formGroup]="formGroup" class="mat-form-field--no-underline">
        <!-- Important part, input with matInput -->
        <input matInput style="display: none!important">
        <mat-selection-list #preConditions [formControl]="preexistingControl" [(ngModel)]="controlAnswer.value">
            <mat-list-option *ngFor="let preExistingCond of preExistingCondList">
                {{preExistingCond.value}}
            </mat-list-option>
        </mat-selection-list>
     </mat-form-field>
如果样式不适用,可以使用ngdeep应用它

  .mat-form-field--no-underline .mat-form-field-underline {
     background-color: transparent !important;
  }