首页 文章

Ng测试 - 可't bind to '值' since it isn' t 'mat-select'的已知属性

提问于
浏览
0

我有一个使用Material Design的Angular6应用程序 . 运行'ng test'时,我收到以下错误:

失败:模板解析错误:无法绑定到'value',因为它不是'mat-select'的已知属性 .

我在进口和出口中加入了MatSelectModule . 它在应用程序中工作正常但在测试期间失败 .

材料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 回答

  • 0

    您是否在spec.ts文件中导入材料模块?

    beforeEach(async(() => {
      TestBed.configureTestingModule({
        imports: [ MaterialDesignModule ],
        declarations: [ FooComponent ]
      })
      .compileComponents();
    }));
    

相关问题