Can not bind to 'matDatePicker' since it is not a known property of 'input' [closed]

2

I'm having trouble including the angular material datepicker in my application.

In my app.module.ts I import it like this:

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { MatFormFieldModule, MatCheckboxModule, MatDatepickerModule } from '@angular/material';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    NgbModule.forRoot(),
    FormsModule,
    AppRoutingModule,
    RoutingAppointment, 
    MatFormFieldModule,
    MatCheckboxModule,
    MatDatepickerModule
  ],
  exports:[
    MatDatepickerModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

And later in my component in the html I call it in the following way (copy paste from the doc of angular material):

<mat-form-field>
      <input matInput [matDatePicker]="picker" placeholder="DD/MM/YYYY">
      <mat-datepicker-toggle matSuffix [for]="picker"></mat-datepicker-toggle>
      <mat-datepicker #picker></mat-datepicker>
    </mat-form-field>

However, he is giving me the error:

  

Can not bind to 'matDatePicker' since it is not a known property of 'input'

Does anyone know what I'm doing wrong?

    
asked by Findelias 25.04.2018 в 09:25
source

2 answers

0

Solved. In the html the name of the attribute was misspelled.

Instead of [matDatepicker] which is the correct way, it had [matDatePicker] with the capital P, which is incorrect.

A nonsense like a grand piano.

    
answered by 25.04.2018 / 11:43
source
0

Sounds like you have not imported the corresponding module:

You have to choose between MatMomentDateModule (which will depend on moment.js ) and MatNativeDateModule (which will use the class Date native Javascript).

On the other hand, make sure you have also imported FormsModule and (depending on what type of forms you create) ReactiveFormsModule .

Well find more information (in English) here

    
answered by 25.04.2018 в 10:13