角度材料中的垫子选项不起作用

时间:2018-05-29 02:38:12

标签: angular angular-material

我正在尝试使用角度为6的角度材料

我的material.module.ts就像这样

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>

给出错误

    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.

请帮忙

2 个答案:

答案 0 :(得分:0)

您不必导出所有与材料相关的模块,

 exports: [
 ]

<强> DEMO

答案 1 :(得分:0)

在提供程序中尝试添加ErrorStateMatcher,useClass:ShowOnDirtyErrorStateMatcher