[英]Ng Test - Can't bind to 'value' since it isn't a known property of 'mat-select'
I have an Angular6 application using Material Design.我有一个使用 Material Design 的 Angular6 应用程序。 When running 'ng test', I get the following error:
运行“ng test”时,出现以下错误:
Failed: Template parse errors: Can't bind to 'value' since it isn't a known property of 'mat-select'.
失败:模板解析错误:无法绑定到“value”,因为它不是“mat-select”的已知属性。
I have included MatSelectModule in my imports and exports.我在导入和导出中包含了 MatSelectModule。 It works fine in the application but fails during testing.
它在应用程序中运行良好,但在测试期间失败。
material-design.module.ts 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 { }
Select example:选择示例:
<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>
Are you importing the material module in your spec.ts file?您是否在 spec.ts 文件中导入材料模块?
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [ MaterialDesignModule ],
declarations: [ FooComponent ]
})
.compileComponents();
}));
You must import MatSelectModule from import { MatSelectModule } from '@angular/material';
您必须从
import { MatSelectModule } from '@angular/material';
导入 MatSelectModule import { MatSelectModule } from '@angular/material';
and add it to your spec imports并将其添加到您的规范导入中
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [ MatSelectModule ],
declarations: [ FooComponent ]
})
.compileComponents();
}));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.