无法绑定到"matDatepicker",因为它不是“输入"的已知属性-Angular [英] Can't bind to 'matDatepicker' since it isn't a known property of 'input' - Angular

查看:228
本文介绍了无法绑定到"matDatepicker",因为它不是“输入"的已知属性-Angular的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚复制并粘贴了用于datePicker的角形材料代码并输入,但是对于datePicker却出现此错误.

I have just copied and pasted angular material code for datePicker and input, but I am getting this error for the datePicker.

app.module

import {MaterialModule} from '@angular/material';
@NgModule({
imports: [
...
MaterialModule
]

<md-input-container>
    <input mdInput placeholder="Rechercher" [(ngModel)]="filterHistorique">
</md-input-container>

<md-input-container>
    <input mdInput [mdDatepicker]="picker" placeholder="Choose a date">
    <button mdSuffix [mdDatepickerToggle]="picker"></button>
</md-input-container>
<md-datepicker #picker></md-datepicker>

这是我在浏览器中遇到的错误:

This is the error I am having in my browser:

无法绑定到"mdDatepicker",因为它不是的已知属性 '输入'如果'md-datepicker'是Angular组件,则验证 它是此模块的一部分. 2.如果"md-datepicker"是Web组件,则将"CUSTOM_ELEMENTS_SCHEMA"添加到该组件的"@ NgModule.schemas" 禁止显示此消息. ("[错误 ->]

Can't bind to 'mdDatepicker' since it isn't a known property of 'input' If 'md-datepicker' is an Angular component, then verify that it is part of this module. 2. If 'md-datepicker' is a Web Component then add "CUSTOM_ELEMENTS_SCHEMA" to the '@NgModule.schemas' of this component to suppress this message. (" [ERROR ->]

错误是针对日期选择器的,当我将其删除时,错误消失了

The error is for the datepicker, when I removed it, the errors disappears

推荐答案

使用mat-datepicker时,您还必须导入MatDatepickerModule,也建议也导入MatNativeDateModule.请参阅文档 此处 .

While using mat-datepicker, you have to import MatDatepickerModule as well, also MatNativeDateModule is recommended to be imported too. see docs here.

import { MaterialModule, MatDatepickerModule, MatNativeDateModule } from '@angular/material';
@NgModule({
  imports: [
    ...
    MaterialModule,            // <----- this module will be deprecated in the future version.
    MatDatepickerModule,        // <----- import(must)
    MatNativeDateModule,        // <----- import for date formating(optional)
    MatMomentDateModule         // <----- import for date formating adapted to more locales(optional)
  ]

有关日期格式的可选模块,请参见

For optional module of date formating, see Module for DateAdapter from material team.

提及:请避免使用MaterialModule,因为将来会不推荐使用.

Mention: please avoid using MaterialModule for it'll be deprecated in the future.

这篇关于无法绑定到"matDatepicker",因为它不是“输入"的已知属性-Angular的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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