Angular 角度8材质不渲染

Angular 角度8材质不渲染,angular,angular-material,Angular,Angular Material,我的Angular 8材质组件未正确渲染。它应如以下示例所示: 但看起来是这样的: 以下是app.module.ts: import { FormsModule } from '@angular/forms'; import {MatFormFieldModule} from '@angular/material/form-field'; @NgModule({ declarations: [ AppComponent, LoginComponent ], imports

我的Angular 8材质组件未正确渲染。它应如以下示例所示:

但看起来是这样的:

以下是app.module.ts:

import { FormsModule } from '@angular/forms';
import {MatFormFieldModule} from '@angular/material/form-field';

@NgModule({
   declarations: [
   AppComponent,
   LoginComponent
],
imports: [
  BrowserModule,
  AppRoutingModule,
  BrowserAnimationsModule,
  FormsModule,
  MatFormFieldModule
],
  providers: [],
  bootstrap: [AppComponent]
})

export class AppModule { }
这是app.component.html

<div class="example-container">
<mat-form-field>
    <input matInput placeholder="Input">
</mat-form-field>

<mat-form-field>
    <textarea matInput placeholder="Textarea"></textarea>
</mat-form-field>

<mat-form-field>
    <mat-select placeholder="Select">
        <mat-option value="option">Option</mat-option>
    </mat-select>
</mat-form-field>

选项

您必须将
MatInputModule
(用于输入和文本区域)和
MatSelectModule
(用于选择)添加到
app.module.ts
文件中

您可以在本页顶部看到组件所需的内容:


我认为您应该使用
MatSelectModule
MatInputModule

因为
MatFormModule
用于
Matform

所以你的模块应该是这样的

import { FormsModule } from '@angular/forms';
import {MatFormFieldModule} from '@angular/material/form-field';

import {MatSelectModule,MatInputModule} from '@angular/material/form-field';

@NgModule({
   declarations: [
   AppComponent,
   LoginComponent
],
imports: [
  BrowserModule,
  AppRoutingModule,
  BrowserAnimationsModule,
  FormsModule,
  MatFormFieldModule,
  MatSelectModule,
  MatInputModule
],
  providers: [],
  bootstrap: [AppComponent]
})

export class AppModule { }
您还可以在style.css文件中导入css

@import "~@angular/material/prebuilt-themes/indigo-pink.css";

是否将材质css添加到styles.scss?示例主题:
@import“~@angular/material/prebuilded themes/indigo pink.css”是的,我已经在样式中导入了深紫色琥珀色主题。SCS您可以尝试停止并重新启动ng服务吗?我刚才尝试过,结果与以前相同我添加了缺少的模块,但没有任何区别您的演示正在工作。我看到我所有的风格都以SCS结尾,就像你们的css一样。这会是一个问题吗?我已经将你的工作代码复制到我的应用程序中,但它似乎不起作用。我可能缺少一些导入或模块吗?是否有任何异常?没有异常,它正常运行但显示不正确我已按照您的建议添加了模块,但没有任何区别