Angular material: MatDatepicker: No provider found for DateAdapter

后端 未结 4 1974
南旧
南旧 2021-01-01 08:27

I\'m trying to use the Datepicker component in Angular Material. Here is my HTML code:



        
相关标签:
4条回答
  • 2021-01-01 08:44

    Official docs: Error: MatDatepicker: No provider found for DateAdapter/MAT_DATE_FORMATS

    The datepicker was built to be date implementation agnostic. This means that it can be made to work with a variety of different date implementations. However it also means that developers need to make sure to provide the appropriate pieces for the datepicker to work with their chosen implementation. The easiest way to ensure this is just to import one of the pre-made modules: MatNativeDateModule, MatMomentDateModule.

    Fix:

    @NgModule({
      imports: [MatDatepickerModule, MatNativeDateModule],
    })
    export class MyApp {}
    
    0 讨论(0)
  • 2021-01-01 08:51

    Angullar 8,9

    import { MatDatepickerModule } from '@angular/material/datepicker';
    import { MatNativeDateModule } from '@angular/material/core';
    

    Angular 7 and below

    import { MatDatepickerModule, MatNativeDateModule } from '@angular/material';
    

    You need to import both MatDatepickerModule and MatNativeDateModule under imports and add MatDatepickerModule under providers

    imports: [
        MatDatepickerModule,
        MatNativeDateModule 
      ],
      providers: [  
        MatDatepickerModule,
        MatNativeDateModule  
      ],
    
    0 讨论(0)
  • 2021-01-01 08:58

    You need to import both MatDatepickerModule and MatNativeDateModule under imports and add MatDatepickerModule under providers

     imports: [
        MatDatepickerModule,
        MatNativeDateModule 
      ],
      providers: [  
        MatDatepickerModule,  
      ],
    
    0 讨论(0)
  • 2021-01-01 09:01

    Just import the

    MatNativeDateModule

    along with the

    MatDatepickerModule

    at the app.module.ts or app-routing.module.ts.

    @NgModule({
    imports: [
        MatDatepickerModule,
        MatNativeDateModule 
    ]
    })
    
    0 讨论(0)
提交回复
热议问题