我有一个使用 Material Design 的 Angular6 应用程序。运行“ng test”时,出现以下错误:
Failed: Template parse errors: Can't bind to 'value' since it isn't a known property of 'mat-select'.
我在导入和导出中包含了 MatSelectModule。它在应用程序中运行良好,但在测试期间失败。
material-design.module.ts
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { MatFormFieldModule, MatInputModule, MatSelectModule} from '@angular/material';
@NgModule({
imports: [MatFormFieldModule, MatInputModule, MatSelectModule],
exports: [MatFormFieldModule, MatInputModule, MatSelectModule],
})
export class MaterialDesignModule { }
选择示例:
<mat-form-field class='select_buttons'>
<mat-select (selectionChange)='typeSelection_changed($event)' [(value)]='type'>
<mat-option *ngFor="let type of types" [value]="type"> {{type.name}}</mat-option>
</mat-select>
</mat-form-field>
最佳答案
按照以下步骤操作 -
import { MatSelectModule } from '@angular/material/select';
在 your-file-name.module.ts在
imports
中添加MatSelectModule
-
@NgModule({
declarations: [MyComponent],
imports: [
MatSelectModule,
]
})
关于testing - Ng 测试 - 无法绑定(bind)到 'value',因为它不是 'mat-select' 的已知属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51791596/