Angular 2 DateTimepicker is a cool responsive DateTimepicker component for Web and Mobile. It is Mobile friendly and light weight. Developed by Cuppa Labs.
To get started with using the multiselect dropdown component, follow the below steps. It’s easy to integrate and just a matter of minutes.
npm install angular2-datetimepicker
Import AngularDateTimePickerModule
into your AppModule
import { AngularDateTimePickerModule } from 'angular2-datetimepicker';
@NgModule({
// ...
imports: [
AngularDateTimePickerModule,
]
// ...
})
Declare the component data variables and options in your component where you want to consume the dropdown component.
import { Component, OnInit } from '@angular/core';
export class AppComponent implements OnInit {
date: Date = new Date();
settings = {
bigBanner: true,
timePicker: false,
format: 'dd-MM-yyyy',
defaultOpen: true
}
constructor(){}
ngOnInit(){
}
}
Add the following component tag in the template where your want to place the datepicker
<angular2-date-picker [(ngModel)]="date" [settings]="settings"></angular2-date-picker>
Following settings
object properties can be used to configure the component.
Property | Type | Default | Description |
---|---|---|---|
format | String | dd-MMM-yyyy hh:mm a | Date format of the selected date. |
bigBanner | Boolean | true | The banner section to show the date details. |
defaultOpen | Boolean | false | To open the datepicker popover on load. Default is set to false. |
timePicker | Boolean | false | Enable time picker feature. |
closeOnSelect | Boolean | true | to close the popover on date select or on click of done button. |
onDateSelect
Define a callback method to be called on select of the date.
<angular2-date-picker (onDateSelect)="onDateSelect($event)"
[(ngModel)]="date"
[settings]="settings" >
</angular2-date-picker>
format string can be composed of the following elements:
format string can also be one of the following predefined localizable formats:
‘medium’: equivalent to ‘MMM d, y h:mm:ss a’ for en_US locale (e.g. Sep 3, 2010 12:05:08 PM)
npm install
ng serve
for a dev serverhttp://localhost:4200/
MIT License.
Thanks to Font Awesome and Moment.js for the libraries.
Pradeep Kumar Terli