Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. When running 'ng test', I get the following error:

Failed: Template parse errors: Can't bind to 'value' since it isn't a known property of 'mat-select'.

I have included MatSelectModule in my imports and exports. It works fine in the application but fails during testing.

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>
like image 999
ellier7 Avatar asked Aug 10 '18 17:08

ellier7


2 Answers

Follow following steps -

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

  2. Add MatSelectModule in imports-

@NgModule({
  declarations: [MyComponent],
  imports: [
    MatSelectModule,
  ]
})
like image 170
Suprabhat Kumar Avatar answered Oct 26 '22 16:10

Suprabhat Kumar


You must import MatSelectModule from import { MatSelectModule } from '@angular/material'; and add it to your spec imports

beforeEach(async(() => {
  TestBed.configureTestingModule({
    imports: [ MatSelectModule ],
    declarations: [ FooComponent ]
  })
  .compileComponents();
}));
like image 20
Takatalvi Avatar answered Oct 26 '22 15:10

Takatalvi