我想使用角度材料日期选择器,但我得到了这个错误。
未知错误:由模块'AppModule‘导入的意外指令'MatFormField’。请添加一个@NgModule注释。
app.component.html
<mat-form-field>
<input matInput [matDatepicker]="picker" placeholder="Choose a date">
<mat-datepicker-toggle matSuffix [for]="picker"></mat-datepicker-toggle>
<mat-datepicker #picker></mat-datepicker>
</mat-form-field>app.module.ts
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
import {MatFormField} from '@angular/material';
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
MatFormField
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }发布于 2018-11-20 16:49:20
要导入组件和指令等,您需要导入它们的模块,而不是实际的组件和指令。所以您需要导入MatFormFieldModule而不是MatFormField
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
import { MatFormFieldModule } from '@angular/material/form-field';
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
MatFormFieldModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }https://stackoverflow.com/questions/53391255
复制相似问题