What is @angular/material-moment-adapter?
@angular/material-moment-adapter is an Angular package that provides a Moment.js adapter for Angular Material's datepicker. It allows you to use Moment.js to parse, format, and manipulate dates within Angular Material components.
What are @angular/material-moment-adapter's main functionalities?
Date Adapter Configuration
This code demonstrates how to configure the Moment.js date adapter in an Angular module. It imports the necessary modules and sets the adapter options to use UTC.
import { NgModule } from '@angular/core';
import { MatDatepickerModule } from '@angular/material/datepicker';
import { MatMomentDateModule, MAT_MOMENT_DATE_ADAPTER_OPTIONS } from '@angular/material-moment-adapter';
@NgModule({
imports: [
MatDatepickerModule,
MatMomentDateModule
],
providers: [
{ provide: MAT_MOMENT_DATE_ADAPTER_OPTIONS, useValue: { useUtc: true } }
]
})
export class AppModule { }
Using Moment.js with Angular Material Datepicker
This code shows how to use Moment.js with Angular Material's datepicker component. It initializes a date using Moment.js and binds it to the datepicker input.
import { Component } from '@angular/core';
import * as moment from 'moment';
@Component({
selector: 'app-datepicker',
template: '<mat-form-field><input matInput [matDatepicker]="picker" placeholder="Choose a date"><mat-datepicker-toggle matSuffix [for]="picker"></mat-datepicker-toggle><mat-datepicker #picker></mat-datepicker></mat-form-field>'
})
export class DatepickerComponent {
selectedDate = moment();
}
Other packages similar to @angular/material-moment-adapter
@angular/material-luxon-adapter
@angular/material-luxon-adapter provides a Luxon adapter for Angular Material's datepicker. Luxon is a modern JavaScript date library that offers a more comprehensive and immutable API compared to Moment.js. It is a good alternative if you prefer using Luxon over Moment.js.
@angular/material-date-fns-adapter
@angular/material-date-fns-adapter provides a date-fns adapter for Angular Material's datepicker. date-fns is a lightweight and modular date library that allows you to import only the functions you need. It is a good alternative if you are looking for a smaller bundle size and tree-shakable date library.
Angular Material
The sources for this package are in the main Angular Material repo. Please file issues and pull requests against that repo.
License: MIT
17.2.2 "metal-marble" (2024-03-06)
cdk
| Commit | Type | Description |
| -- | -- | -- |
| 4af777a189 | fix | drag-drop: resolve helper directives with DI for proper hostDirectives support (#28633) |
| 94eafc134f | fix | overlay: fix overlay margin in isBoundedByLeftViewportEdge ('left-ward') mode (#28233) |
material
| Commit | Type | Description |
| -- | -- | -- |
| 65aaaf3abf | fix | autocomplete: prevent hidden overlay from blocking clicks (#28677) |
| d08ddaab81 | fix | autocomplete: requireSelection sometimes not clearing value when editing after selection (#28628) |
| 5b3210bfda | fix | checkbox: derive checkmark color from palette |
| fb20320b82 | fix | chips: derive surface color from palette |
| fe01e298a0 | fix | core: mark fields on HasErrorState as nullable (#28689) |
| afbb34e415 | fix | datepicker: always move caret to the end of the start input on backspace (#28669) |
| ec6f8e2e62 | fix | datepicker: datepicker doesn't announce newly selected range in firefox (#28529) |
| ba6e809761 | fix | expansion: prevent focus from entering the panel while it's animating (#28646) |
| 07f5ed9dc6 | fix | schematics: add typography and density to custom theme (#28645) |
| 6d8160c166 | fix | schematics: don't interrupt ng add if adding the animations module fails (#28675) |
| 9655ecb872 | fix | slide-toggle: m3 selected track outline (#28625) (#28634) |
| 7d352fbf88 | perf | form-field: resolve scrolling performance issues (#27251) |
material-experimental
| Commit | Type | Description |
| -- | -- | -- |
| f18ef99785 | feat | theming: provide hook for formatting toke… (#28660) |
multiple
| Commit | Type | Description |
| -- | -- | -- |
| 14c055fe07 | fix | derive all token values from theme (#28664) |
<!-- CHANGELOG SPLIT MARKER -->
<a name="17.2.1"></a>