Angular 8输入材质未设置样式

时间:2019-12-12 09:07:38

标签: html angular angular-material

当前输入字段如下:

enter image description here

我的一个组件具有以下HTML:

<form class="example-form">
  <mat-form-field class="example-full-width">
    <input matInput placeholder="Favorite food" value="Sushi">
  </mat-form-field>

  <mat-form-field class="example-full-width">
    <textarea matInput placeholder="Leave a comment"></textarea>
  </mat-form-field>
</form>

我的app.module.ts具有以下问题:

enter image description here

为什么输入的样式不像examples那样?

enter image description here

1 个答案:

答案 0 :(得分:1)

尝试在NgModule中导入“物料表单字段模块”。 另外,还需要在style.scss

中添加Material CSS
@import '~@angular/material/prebuilt-themes/deeppurple-amber.css';

然后在app.module.ts中添加MatInputModule

import {MatInputModule,MatFormFieldModule} from '@angular/material';

// ....
imports: [
    MatFormFieldModule,
    MatInputModule,
    ...
],

请参阅文档:Form-FieldExample