简体   繁体   English

Ng 测试 - 无法绑定到“value”,因为它不是“mat-select”的已知属性

[英]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.

相关问题 错误:“NG0303:无法绑定到‘max’,因为它不是‘mat-progress-bar’的已知属性。” 同时 angular 测试 - ERROR: 'NG0303: Can't bind to 'max' since it isn't a known property of 'mat-progress-bar'.' while angular testing 许多失败:模板解析错误:无法绑定到“routerLink”,因为它不是“a”的已知属性。 Karma 中的错误 - Lots of Failed: Template parse errors: Can't bind to 'routerLink' since it isn't a known property of 'a'. errors in Karma 使用 Karma 进行测试-无法绑定到“routerLink”,因为它不是 - Testing with Karma- Can't bind to 'routerLink' since it isn't a known property of angular2 测试:无法绑定到“ngModel”,因为它不是“input”的已知属性 - angular2 testing: Can't bind to 'ngModel' since it isn't a known property of 'input' TEST ECX,3未测试ECX指向的值 - TEST ECX, 3 isn't testing the value pointed to by ECX 使用 mat-select 和 formControlName 测试 Angular 组件的 karma 错误 - Error at karma testing an Angular component using mat-select and formControlName 无法在使用 Mockito 的测试中正确初始化 lateinit 属性(类) - Can't initialize lateinit property (class) properly in test using Mockito 我的Junit测试无效 - My Junit test isn't working JestJS:异步测试没有停止 - JestJS: Async test isn't stopped ng 测试找不到相对路径 - ng test don't find relative path
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM