2

I am trying to use angular-material with angular-6

My material.module.ts is like this

import { NgModule } from '@angular/core';
import { MatButtonModule } from '@angular/material';
import { MatFormFieldModule } from '@angular/material/form-field';
import { MatIconModule } from '@angular/material/icon';
import { MatTableModule } from '@angular/material/table';
import { MatSelectModule } from '@angular/material/select';
import { MatInputModule } from '@angular/material/input';

@NgModule({
  imports: [
    MatButtonModule,
    MatIconModule,
    MatTableModule,
    MatFormFieldModule,
    MatSelectModule,
    MatInputModule
  ],
  exports: [
    MatButtonModule,
    MatIconModule,
    MatTableModule,
    MatFormFieldModule,
    MatSelectModule,
    MatInputModule
  ]
})
export class MaterialModule {}




<mat-form-field>
       <mat-select placeholder="Favorite food">
                <mat-option *ngFor="let food of foods" [value]="food.value">
                            {{ food.viewValue }}
                        </mat-option>
                    </mat-select>
                </mat-form-field>

It is giving error

    Uncaught Error: Template parse errors:
Can't bind to 'ngForOf' since it isn't a known property of 'mat-option'.
1. If 'mat-option' is an Angular component and it has 'ngForOf' input, then verify that it is part of this module.

Please help

raju
  • 6,448
  • 24
  • 80
  • 163
  • 2
    Possible duplicate of [Can't bind to 'ngForOf' since it isn't a known property of 'tr' (final release)](https://stackoverflow.com/questions/40331549/cant-bind-to-ngforof-since-it-isnt-a-known-property-of-tr-final-release) – Shift 'n Tab May 29 '18 at 05:39

2 Answers2

-1

You do not have to export all the Material related modules,

 exports: [
 ]

DEMO

Sajeetharan
  • 216,225
  • 63
  • 350
  • 396
-1

in providers try to add ErrorStateMatcher, useClass: ShowOnDirtyErrorStateMatcher

swagath
  • 125
  • 1
  • 3
  • 10