mat-form-field'不是角度的已知元素 [英] mat-form-field' is not a known element in angular

查看:63
本文介绍了mat-form-field'不是角度的已知元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用角度材料的输入,但出现此错误** src/app/modules/posts/posts.component.html:2:5中的错误-错误NG8001:"mat-form-field"不是已知元素:1.如果"mat-form-field"是一个Angular组件,则请验证它是否是此模块的一部分.2.如果"mat-form-field"是一个Web组件,则将"CUSTOM_ELEMENTS_SCHEMA"添加到该组件的"@ NgModule.schemas"以禁止显示此消息.

i am using input from angular material but i get this error **ERROR in src/app/modules/posts/posts.component.html:2:5 - error NG8001: 'mat-form-field' is not a known element: 1. If 'mat-form-field' is an Angular component, then verify that it is part of this module. 2. If 'mat-form-field' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.

这是我的html代码

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


  </form>

这是我的应用模块

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';

import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { DefaultModule } from './layouts/default/default.module';
import { MatTableModule } from '@angular/material/table';
import { HttpClientModule } from '@angular/common/http';
import {UserInfoService} from './services/user-info.service'
import {MatCardModule} from '@angular/material/card';
import {MatDialogModule} from '@angular/material/dialog';
import { PostsComponent } from './modules/posts/posts.component';
import {  MatFormFieldModule} from '@angular/material/form-field';
import {MatInputModule} from '@angular/material/input';

@NgModule({
  declarations: [
    AppComponent,



  ],
  imports: [
    BrowserModule,
    AppRoutingModule,
    BrowserAnimationsModule,
    DefaultModule,
    MatTableModule,
    HttpClientModule,
    MatCardModule,
    MatDialogModule,
    MatFormFieldModule,
    MatInputModule
  ],
  exports: [

    MatFormFieldModule,
    MatInputModule,

  ],
  providers: [UserInfoService],
  bootstrap: [AppComponent],
  entryComponents:[PostsComponent]
})
export class AppModule { }

我找不到合适的解决方案,您能帮我吗?

i can not find the right solution for this can you help me?

推荐答案

imports 部分添加 FormsModule,ReactiveFormsModule .删除两个 exports 元素.

Add FormsModule, ReactiveFormsModule, to imports section. Remove both exports elements.

这篇关于mat-form-field'不是角度的已知元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆