skip to content

Datepickers & Date Adapters

The datepicker and timepicker read and write dates through a DateAdapter, so the adapter you provide sets the date type, parsing and locale. Interviewers ask why dates show in the wrong format.

part ofAngular Material & CDKread it →
on this pageshow

explore

questions

6

In Angular Material 22, how do you wire a mat-datepicker and its toggle to a text input, and what must the app provide first?

level: juniorimportance: must knowfreq 48%

answer

  1. three pieces, one template reference
  2. the input carries the picker binding
  3. the toggle names its picker
  4. no date implementation, no datepicker
  5. a provide-adapter function in app config

basics

~10 s

Give the mat-datepicker a template reference, bind the input with [matDatepicker]="picker" and the mat-datepicker-toggle with [for]="picker", and provide a DateAdapter, for example provideNativeDateAdapter(), in the app config; without one the datepicker throws.

solid answer

~40 s

A Material datepicker is three cooperating pieces: the native `input` that holds the value, the `mat-datepicker` calendar pop-up, and an optional `mat-datepicker-toggle` button. You give the picker a template reference such as `#pickupPicker`, bind the input with `[matDatepicker]="pickupPicker"` and the toggle with `[for]="pickupPicker"`, and import `MatDatepickerModule` into the standalone component. The piece people forget is the date implementation: the datepicker reads, parses and formats every date through an injected `DateAdapter` and `MAT_DATE_FORMATS`, so the app config must call `provideNativeDateAdapter()` or the date-fns, Luxon or Moment provider function. In development mode, leaving it out throws `MatDatepicker: No provider found for DateAdapter`. Keep the toggle even though Alt + Down Arrow opens the calendar from the input, because some platforms swallow that shortcut.

code

ts · 9 lines
ts
import {ApplicationConfig} from '@angular/core';
import {provideNativeDateAdapter} from '@angular/material/core';

export const appConfig: ApplicationConfig = {
  providers: [
    // Registers DateAdapter (NativeDateAdapter) and MAT_DATE_FORMATS
    provideNativeDateAdapter(),
  ],
};

go deeper

for a junior

Recall the three pieces and the two bindings: [matDatepicker] on the input, [for] on the toggle, both pointing at the picker's template reference.

for a middle

Explain why the datepicker needs an injected DateAdapter and MAT_DATE_FORMATS, what the provide-adapter functions register, and why they go in providers rather than imports.

for a senior

Show you have debugged it: the missing-provider error, one picker per input, dateInput versus dateChange, and why the toggle stays for accessibility.

for a principal

Frame the adapter as the seam that lets one calendar serve any date library, and decide where in the injector tree a product's date implementation should be provided.

## What a Material datepicker is made of Angular Material's datepicker is not a single element. It is a small set of pieces that find each other through a **template reference variable** and through **dependency injection**: - **The input**: a native `<input>` carrying the `matDatepicker` directive (selector `input[matDatepicker]`). It holds the value, parses what the user types, runs the date validators and plugs into `@angular/forms` through `formControl`, `formControlName` or `ngModel`. - **The pop-up**: `<mat-datepicker>`, the calendar panel. It renders nothing until it is opened. - **The toggle**: `<mat-datepicker-toggle>`, an optional icon button whose `for` input names the picker it opens. Its icon can be replaced by projecting an element marked `matDatepickerToggleIcon`. - **The date implementation**: a `DateAdapter` plus a `MAT_DATE_FORMATS` object, both provided by injection. Every date the other pieces read, parse, compare or display passes through them. ## Wiring it in a standalone component For a car-rental reservation page, the pick-up date field looks like this: ```ts import {Component} from '@angular/core'; import {MatDatepickerModule} from '@angular/material/datepicker'; import {MatFormFieldModule} from '@angular/material/form-field'; import {MatInputModule} from '@angular/material/input'; @Component({ selector: 'app-pickup-date', imports: [MatDatepickerModule, MatFormFieldModule, MatInputModule], template: ` <mat-form-field> <mat-label>Pick-up date</mat-label> <input matInput [matDatepicker]="pickupPicker"> <mat-datepicker-toggle matIconSuffix [for]="pickupPicker" /> <mat-datepicker #pickupPicker /> </mat-form-field> `, }) export class PickupDate {} ``` The reference `#pickupPicker` is the glue: the input and the toggle both receive the same `MatDatepicker` instance. The form field around the input is optional; the datepicker works on a bare input too. ## Providing the date implementation The component above compiles, but it cannot run until the application provides a date implementation: 1. Pick an adapter. `provideNativeDateAdapter()` from `@angular/material/core` works with JavaScript `Date` objects and adds no dependency. 2. For real parsing and locale support, use `provideDateFnsAdapter()`, `provideLuxonDateAdapter()` or `provideMomentDateAdapter()` from `@angular/material-date-fns-adapter`, `@angular/material-luxon-adapter` or `@angular/material-moment-adapter`. 3. Put the call in the `providers` array of `bootstrapApplication` or the app config. These functions return providers for `DateAdapter` and `MAT_DATE_FORMATS`; they are not components and do not belong in a component's `imports`. ## Errors you meet first | Message | Cause | Fix | |---|---|---| | `MatDatepicker: No provider found for DateAdapter` | no adapter provided anywhere in the injector tree | add a provide-adapter function | | `MatDatepicker: No provider found for MAT_DATE_FORMATS` | a custom `DateAdapter` provided without formats | provide `MAT_DATE_FORMATS` too | | `A MatDatepicker can only be associated with a single input.` | two inputs bind the same picker | one picker per input | | `Attempted to open an MatDatepicker with no associated input.` | the picker is opened but no input references it | bind an input with `[matDatepicker]` | The provider checks run in development mode; a production build without an adapter still breaks, only less legibly. ## Toggle and event details worth knowing - **Disabled state** flows from the input: the picker and toggle inherit it unless you set `disabled` on them directly, which lets you lock typing but allow calendar selection, or the reverse. - **Keyboard**: the input opens the calendar on Alt + Down Arrow, but the Material guide notes that ChromeOS intercepts that combination and that mobile screen-reader users have no way to open the dialog without the icon button. Keep the toggle. - **Events**: the input's native `(input)` and `(change)` events fire only for typing. Use `(dateInput)`, which fires whenever the value changes from typing or the calendar, and `(dateChange)`, which fires when typing ends on blur or when a calendar date is chosen. - **Value type**: what the input holds is decided by the adapter, a `Date` with the native and date-fns adapters, a Luxon `DateTime` or a `Moment` with the others.

  • Why does the Material guide tell you to keep the datepicker toggle when Alt + Down Arrow already opens the calendar from the input?
    Because the shortcut is not reliable everywhere. ChromeOS intercepts Alt + Down Arrow at the operating-system level, so the browser only sees a Page Down key, and mobile screen-reader users have no way to trigger the calendar dialog without the icon button. The toggle is the one trigger that works for everyone.
  • Why does a (change) handler on a datepicker input miss dates picked from the calendar, and what do you listen to instead?
    Native `input` and `change` events only fire from typing in the element. The datepicker input adds `(dateInput)`, which fires on every value change from typing or the calendar, and `(dateChange)`, which fires when typing is committed on blur or a calendar date is chosen. With a form control you can also watch the control's value.
  • What happens if a return-date input and a pick-up input both bind [matDatepicker] to the same picker reference?
    The second registration throws `A MatDatepicker can only be associated with a single input.` Each input needs its own `mat-datepicker`. For a linked pick-up and return pair, use `mat-date-range-input` with one `mat-date-range-picker` instead.

  • The datepicker works with no providers because dates are just JavaScript Date objects.
  • The toggle finds its picker automatically because it sits inside the same form field.
  • A native (change) listener on the input catches dates chosen from the calendar.
  • Alt plus Down Arrow opens the calendar, so the toggle button is decoration.
  • provideNativeDateAdapter() goes into a component's imports array next to MatDatepickerModule.
open as a page

In Angular Material 22, what do DateAdapter, MAT_DATE_FORMATS and MAT_DATE_LOCALE each decide, and how do you set them for German dates held as Luxon values?

level: middleimportance: must knowfreq 40%

basics

~20 s

DateAdapter decides the date type and how dates are parsed, formatted and compared; MAT_DATE_FORMATS holds the parse and display formats that adapter understands; MAT_DATE_LOCALE sets its locale. For Luxon: provideLuxonDateAdapter(germanFormats) plus MAT_DATE_LOCALE set to 'de'.

open as a page

With Angular Material's mat-date-range-input, how do you build a pick-up and return range that blocks unavailable dates, and what does the filter miss?

level: middleimportance: should knowfreq 34%

basics

~20 s

Wrap matStartDate and matEndDate inputs in mat-date-range-input, link it to a mat-date-range-picker with [rangePicker], and block days with [dateFilter], [min] and [max]. The filter only validates the two endpoints, so a range can still span a blocked day.

open as a page

German users of an Angular Material datepicker on provideNativeDateAdapter see 12.10.2026 in the input, but typing dates that way fails or lands on the wrong month; why, and what fixes it?

level: seniorimportance: should knowfreq 37%

basics

~20 s

NativeDateAdapter formats through Intl.DateTimeFormat in the German locale but parses typed text with Date.parse, ignoring both locale and parse format, so day-first text is rejected or read month-first. Switch to the date-fns, Luxon or Moment adapter with a German parse format.

open as a page

A Berlin car-rental page posts the date chosen in an Angular Material datepicker using the native adapter, and the server stores the day before; why, and how does the Luxon adapter fix it?

level: seniorimportance: should knowfreq 31%

basics

~20 s

The native adapter creates local-midnight Date values and JSON serialisation converts them to UTC, so 12 October in Berlin is sent as 2026-10-11T22:00Z. With Luxon, send toISODate(), or set useUtc or, since 22.2, a timeZone in MAT_LUXON_DATE_ADAPTER_OPTIONS.

open as a page

In Angular Material 22, how do you restrict mat-timepicker to pick-up slots every 15 minutes between 08:00 and 18:00, and when do you use its options input instead?

level: seniorimportance: nice to knowfreq 24%

basics

~10 s

Bind the input with [matTimepicker], set interval="15m" on mat-timepicker and matTimepickerMin="08:00" and matTimepickerMax="18:00" on the input. Use the options input, an array of value-label objects, for irregular slots; setting both interval and options throws.

open as a page