16.0.1 • Published 9 months ago

@angular-material-components/datetime-picker v16.0.1

Weekly downloads
23,858
License
MIT
Repository
github
Last release
9 months ago

Angular Material DatetimePicker, Timepicker for @angular/material 7.x, 8.x, 9.x, 10.x, 11.x, 12.x, 13.x, 14.x, 15.x, 16.x

Build Status License npm version Github All Releases

Description

A DatetimePicker like @angular/material Datepicker by adding support for choosing time.

DEMO

@see LIVE DEMO AND DOCUMENTATION

@see DEMO stackblitz

Alt Text

Choose the version corresponding to your Angular version:

Angular@angular-material-components/datetime-picker
1616.x+
1515.x+ OR 9.x+ for legacy import
148.x+
137.x+
126.x+
115.x+
104.x+
92.x+
82.x+
72.x+

Getting started

npm install --save  @angular-material-components/datetime-picker

Setup

Basically the same way the @angular/material Datepicker is configured and imported.

import { NgxMatDatetimePickerModule, NgxMatTimepickerModule } from '@angular-material-components/datetime-picker';
@NgModule({
   ...
   imports: [
      BrowserModule,
      HttpClientModule,
      BrowserAnimationsModule,
      MatDatepickerModule,
      MatInputModule,
      NgxMatTimepickerModule,
      FormsModule,
      ReactiveFormsModule,
      MatButtonModule,
      NgxMatDatetimePickerModule,
   ],
   ...
})
export class AppModule { }

@see src/app/demo-datetime/demo-datetime.module.ts

Using the component

The same API as @angular/material Datepicker (@see API docs)

Datetime Picker (ngx-mat-datetime-picker)

<mat-form-field>
   <input matInput [ngxMatDatetimePicker]="picker" placeholder="Choose a date" [formControl]="dateControl"
      [min]="minDate" [max]="maxDate" [disabled]="disabled">
   <mat-datepicker-toggle matSuffix [for]="picker"></mat-datepicker-toggle>
   <ngx-mat-datetime-picker #picker [showSpinners]="showSpinners" [showSeconds]="showSeconds"
      [stepHour]="stepHour" [stepMinute]="stepMinute" [stepSecond]="stepSecond"
      [touchUi]="touchUi" [color]="color" [enableMeridian]="enableMeridian" 
      [disableMinute]="disableMinute" [hideTime]="hideTime">
   </ngx-mat-datetime-picker>
</mat-form-field>

Timepicker (ngx-mat-timepicker)

<ngx-mat-timepicker [(ngModel)]="date"></ngx-mat-timepicker>
<ngx-mat-timepicker [(ngModel)]="date" [disabled]="disabled"></ngx-mat-timepicker>
<ngx-mat-timepicker [(ngModel)]="date" [stepHour]="2" [stepMinute]="5" [stepSecond]="10"></ngx-mat-timepicker>
<ngx-mat-timepicker [(ngModel)]="date" [showSpinners]="showSpinners"></ngx-mat-timepicker>
<ngx-mat-timepicker [(ngModel)]="date" [showSeconds]="showSeconds"></ngx-mat-timepicker>
<ngx-mat-timepicker [(ngModel)]="date" [disableMinute]="disableMinute"></ngx-mat-timepicker>
<ngx-mat-timepicker [(ngModel)]="date" [defaultTime]="defaultTime"></ngx-mat-timepicker>
<ngx-mat-timepicker [formControl]="formControl"></ngx-mat-timepicker>

List of @Input of ngx-mat-timepicker

You can use all @Input of ngx-mat-timepicker for ngx-mat-datetime-picker

@InputTypeDefault valueDescription
disabledbooleannullIf true, the picker is readonly and can't be modified
showSpinnersbooleantrueIf true, the spinners above and below input are visible
showSecondsbooleantrueIf true, it is not possible to select seconds
disableMinutebooleanfalseIf true, the minute (and second) is readonly
defaultTimeArrayundefinedAn array hour, minute, second for default time when the date is not yet defined
stepHournumber1The number of hours to add/substract when clicking hour spinners
stepMinutenumber1The number of minutes to add/substract when clicking minute spinners
stepSecondnumber1The number of seconds to add/substract when clicking second spinners
colorThemePaletteundefinedColor palette to use on the datepicker's calendar.
enableMeridianbooleanfalseWhether to display 12H or 24H mode.
hideTimebooleanfalseIf true, the time is hidden.
touchUibooleanfalseWhether the calendar UI is in touch mode. In touch mode the calendar opens in a dialog rather than a popup and elements have more padding to allow for bigger touch targets.

Choosing a date implementation and date format settings

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 to import one of the provided date modules:

NgxMatNativeDateModuleNgxMatMomentModule
Date typeDateMoment
Supported localesen-USSee project for details
DependenciesNoneMoment.js
Import from@angular-material-components/datetime-picker@angular-material-components/moment-adapter

To use NgxMatMomentModule:

npm install --save  @angular-material-components/moment-adapter

Please note: NgxMatNativeDateModule is based off the functionality available in JavaScript's native Date object. Thus it is not suitable for many locales. One of the biggest shortcomings of the native Date object is the inability to set the parse format.

We highly recommend using the NgxMatMomentModule or a custom NgxMatDateAdapter that works with the formatting/parsing library of your choice.

For example:

Creating a custom date adapter:

@Injectable()
export class CustomDateAdapter extends NgxMatDateAdapter<D> {...}
// D can be Date, Moment or customized type

Creating a custom date adapter module

@NgModule({
  providers: [
    {
      provide: NgxMatDateAdapter,
      useClass: CustomDateAdapter,
      deps: [MAT_DATE_LOCALE, NGX_MAT_MOMENT_DATE_ADAPTER_OPTIONS]
    }
  ],
})
export class CustomDateModule { }

You can also customize the date format by providing your custom NGX_MAT_DATE_FORMATS in your module.

// If using Moment
const CUSTOM_DATE_FORMATS: NgxMatDateFormats = {
  parse: {
    dateInput: "l, LTS"
  },
  display: {
    dateInput: "l, LTS",
    monthYearLabel: "MMM YYYY",
    dateA11yLabel: "LL",
    monthYearA11yLabel: "MMMM YYYY"
  }
};

//and in the module providers 
providers: [
    { provide: NGX_MAT_DATE_FORMATS, useValue: CUSTOM_MOMENT_FORMATS }
  ]

Theming

<link href="https://fonts.googleapis.com/icon?family=Material+Icons&display=block" rel="stylesheet">

License

MIT

15.0.0

9 months ago

15.0.0-beta

9 months ago

15.0.0-rc.1

9 months ago

16.0.1

9 months ago

16.0.0

9 months ago

9.0.0

1 year ago

8.0.0

2 years ago

7.0.0

2 years ago

7.0.1

2 years ago

5.1.1

3 years ago

6.0.3

3 years ago

6.0.1

3 years ago

6.0.0

3 years ago

6.0.2

3 years ago

5.1.0

3 years ago

5.0.3

3 years ago

5.0.2

3 years ago

4.0.7

3 years ago

4.0.6

3 years ago

5.0.1

3 years ago

5.0.0

3 years ago

5.0.0-beta.1

3 years ago

4.0.5

4 years ago

4.0.4

4 years ago

4.0.3

4 years ago

4.0.2

4 years ago

4.0.1-beta.2

4 years ago

4.0.1

4 years ago

4.0.1-beta.1

4 years ago

4.0.0-beta.3

4 years ago

4.0.0

4 years ago

4.0.0-beta.2

4 years ago

4.0.0-beta.1

4 years ago

2.0.4

4 years ago

2.0.3

4 years ago

2.0.2

4 years ago

2.0.1

4 years ago

2.0.0

4 years ago

1.0.1

4 years ago

1.0.0-beta.1

4 years ago