简体   繁体   English

无法绑定到“matDatepicker”,因为它不是“输入”的已知属性

[英]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">

在此处输入图像描述 What I missed?我错过了什么?

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.modulematerial-shared.module并在其中导入材料组件,并在需要时在每个模块中导入此共享模块。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法绑定到“matDatepicker”,因为它不是“input”的已知属性 - Angular - Can't bind to 'matDatepicker' since it isn't a known property of 'input' - Angular Angular9-MatDatePicker:无法绑定到“ngModel”,因为它不是“输入”的已知属性 - Angular9-MatDatePicker: Can't bind to 'ngModel' since it isn't a known property of 'input' 无法绑定到“matDatepicker”,因为它不是“div”的已知属性 - Angular - Can't bind to 'matDatepicker' since it isn't a known property of 'div' - Angular 无法绑定到“shouldLabelFloat”,因为它不是“input”的已知属性 - Can't bind to 'shouldLabelFloat' since it isn't a known property of 'input' 无法绑定到“ngValue”,因为它不是“input”的已知属性 - Can't bind to 'ngValue' since it isn't a known property of 'input' “无法绑定到‘ngModel’,因为它不是‘输入’的已知属性” - “Can't bind to 'ngModel' since it isn't a known property of 'input' ” 无法绑定到“ngModel”,因为它不是“输入”的已知属性 - Can’t bind to ‘ngModel’ since it isn’t a known property of ‘input’ 无法绑定到&#39;mdDatepicker&#39;,因为它不是&#39;input&#39;的已知属性 - Can't bind to 'mdDatepicker' since it isn't a known property of 'input' 无法绑定到“ngModel”,因为它不是“输入”的已知属性 - Can't bind to 'ngModel' since it isn't a known property of 'input' 无法绑定到“上载器”,因为它不是“输入”的已知属性 - Can't bind to 'uploader' since it isn't a known property of 'input'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM