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

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

问题描述

我刚刚复制并粘贴了 datePicker 和 input 的角度材质代码,但我收到了 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",因为它不是'input' 如果 'md-datepicker' 是一个 Angular 组件,则验证它是这个模块的一部分.2.如果'md-datepicker'是一个Web组件,那么在这个组件的'@NgModule.schemas'中添加CUSTOM_ELEMENTS_SCHEMA"抑制此消息.("[错误->]

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)
  ]

关于日期格式的可选模块,请参见DateAdapter 模块 来自材料团队.

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",因为它不是“input"的已知属性 - Angular的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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