[英]Can't bind to 'matDatepicker' since it isn't a known property of 'input'
I am going to use a material date picker controller.我将使用材料日期选择器 controller。 But it shows an error.
但它显示一个错误。 Of course, I added MatDatepickerModule in app.module.ts file.
当然,我在 app.module.ts 文件中添加了 MatDatepickerModule。 Let me show you some parts of my code here:
让我在这里向您展示我的代码的一些部分:
import { MatDatepickerModule } from '@angular/material/datepicker';
...
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
AppRoutingModule,
...,
MatDatepickerModule,
SharedModule.forRoot(),
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule {}
This is html code:这是 html 代码:
<mat-form-field appearance="fill">
<mat-label>Event start time</mat-label>
<input matInput [matDatepicker]="picker">
<mat-datepicker-toggle matSuffix [for]="picker"></mat-datepicker-toggle>
<mat-datepicker #picker></mat-datepicker>
</mat-form-field>
And below is the error log:以下是错误日志:
Error: src/app/.../test.component.html:67:31 - error NG8002: Can't bind to 'matDatepicker' since it isn't a known property of 'input'.
67 <input matInput [matDatepicker]="picker">
You have to import MatDatepickerModule
where your components are declared.您必须在声明组件的地方导入
MatDatepickerModule
。
@NgModule({
declarations: [
AppComponent //Date picker is only available in this component
],
imports: [
...
MatDatepickerModule
]
})
export class AppModule {}
Assuming you have hallway.module
假设你有
hallway.module
@NgModule({
declarations: [
HallwayComponent
],
imports: [
...
MatDatepickerModule //Import it here too, to make it available in Hallway component
]
})
export class HallwayModule {}
You can also create shared.module
or material-shared.module
and import material components in it and import this shared module in every module wherever required.您还可以创建
shared.module
或material-shared.module
并在其中导入材料组件,并在需要时在每个模块中导入此共享模块。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.