【问题标题】:mat-option in angular material not working角材料中的垫子选项不起作用
【发布时间】:2018-11-07 14:11:21
【问题描述】:

我正在尝试将 angular-material 与 angular-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.

请帮忙

【问题讨论】:

标签: angular angular-material


【解决方案1】:

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

 exports: [
 ]

DEMO

【讨论】:

    【解决方案2】:

    在providers中尝试添加ErrorStateMatcher,使用Class: ShowOnDirtyErrorStateMatcher

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-04-30
      • 1970-01-01
      • 1970-01-01
      • 2021-02-17
      • 1970-01-01
      • 1970-01-01
      • 2019-11-22
      相关资源
      最近更新 更多