testing - Ng 测试 - 无法绑定(bind)到 'value',因为它不是 'mat-select' 的已知属性

标签 testing angular-material angular-cli angular6

我有一个使用 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>

最佳答案

按照以下步骤操作 -

  1. import { MatSelectModule } from '@angular/material/select';your-file-name.module.ts

  2. imports中添加MatSelectModule-

@NgModule({
  declarations: [MyComponent],
  imports: [
    MatSelectModule,
  ]
})

关于testing - Ng 测试 - 无法绑定(bind)到 'value',因为它不是 'mat-select' 的已知属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51791596/

相关文章:

testing - mock 无法计算 Facade 上的方法调用

testing - 如何开始构建使用 TypeMock ?

angular-cli - 'compilation' 参数必须是 Compilation 的实例

angular - 删除 Angular 开发服务器中的 "App Ready"状态栏

javascript - 使用 mocha 重用场景

java - Alexa BDD 测试

javascript - 如何从 Angular 模板后端的下拉列表中获取值

angular - 从 Angular 5 升级到 Angular 6 后 : Current document does not have a doctype

css - 如何更改在 Angular Material 的 md-select 中选择的元素的颜色?

angular - 在 scss 中使用 angular 时,如何查看翻译后的 css?