0

I am implementing an application using Angular 15. I use Angular Material there. I need to add a date picker and after inserting the code snippet below I'm getting an error.

<mat-form-field appearance="outline">
        <mat-label>Choose a date</mat-label>
      <input formControlName="freshness" matInput [matDatepicker]="picker">
        <mat-datepicker-toggle matIconSuffix [for]="picker"></mat-datepicker-toggle>
        <mat-datepicker #picker></mat-datepicker>
    </mat-form-field>

Error:

Error: src/app/dialog/dialog.component.html:18:51 - error NG8002: Can't bind to 'matDatepicker' since it isn't a known property of 'input'.

18       <input formControlName="freshness" matInput [matDatepicker]="picker">

If you need further information to solve my issue please put a comment here.

Amer
  • 6,162
  • 2
  • 8
  • 34

1 Answers1

1

The following modules should be imported into your component if it's a standalone component (otherwise, in your module imports):

Besides, make sure you also import the MatInputModule and MatFormFieldModule to make them work.

Amer
  • 6,162
  • 2
  • 8
  • 34
  • 1
    Thank you for your support. I have imported both `MatDatepickerModule, MatNativeDateModule` together. Then I imported them independently.Now error is solved. Angular versions after 10, these 2 should be imported independently. – Nimasha Madhushani Jan 06 '23 at 13:25