项目作者: martre3

项目描述 :
Angular 2+ datepicker component with no JQuery dependency.
高级语言: TypeScript
项目地址: git://github.com/martre3/ngx-dates-picker.git
创建时间: 2019-09-04T11:04:31Z
项目社区:https://github.com/martre3/ngx-dates-picker

开源协议:MIT License

下载


ngx-dates-picker

Angular 2+ datepicker component with no JQuery dependency, forked from bleenco/ng2-datepicker.

AbstruseCI








Installation

  1. Install package from npm.
  1. npm install ngx-dates-picker --save
  1. Include NgxDatesPickerModule into your application.
  1. import { NgModule } from '@angular/core';
  2. import { BrowserModule } from '@angular/platform-browser';
  3. import { NgxDatesPickerModule } from 'ngx-dates-picker';
  4. @NgModule({
  5. imports: [
  6. BrowserModule,
  7. NgxDatesPickerModule
  8. ],
  9. declarations: [ AppComponent ],
  10. exports: [ AppComponent ]
  11. })
  12. export class AppModule {}

Example

  1. <ngx-dates-picker [(ngModel)]="date" ></ngx-dates-picker>

NgModel

Accepted types are date string, javascript Date object and DateRange object ({start: Date, end: Date}).
If selectRange is true javascript Date object will be returned for selected date, else - DateRange object,
where range.start will be equal to range.end if one day is selected.

Attributes

Name Type Default Description
headless boolean false Disable datepicker’s input
isOpened boolean false Show or hide datepicker
position string bottom-right Dropdown position (bottom-left, bottom-right, top-left, top-right, static)
previousMonthButtonTemplate TemplateRef undefined Overrides left arrow used to go one month back.
nextMonthButtonTemplate TemplateRef undefined Overrides right arrow used to go to next month.
options object see options

Options" class="reference-link">Options

  1. defaultOptions: DatepickerOptions = {
  2. closeOnClickOutside: true;
  3. closeOnSelection: true;
  4. selectRange: false,
  5. includeDays: 'previous-month'; // 'none', 'previous-month', 'next-month', 'all'. Should it render days outside current month.
  6. minYear: 1970,
  7. maxYear: 2030,
  8. displayFormat: 'MMM D[,] YYYY',
  9. barTitleFormat: 'MMMM YYYY',
  10. dayNamesFormat: 'ddd',
  11. rangeSeparator: '-' // Char that separates start and end dates in input field.
  12. firstCalendarDay: 0, // 0 - Sunday, 1 - Monday
  13. locale: {},
  14. minDate: undefined, // Minimal selectable date
  15. maxDate: undefined, // Maximal selectable date
  16. barTitleIfEmpty: '',
  17. placeholder: '', // HTML input placeholder attribute (default: '')
  18. addClass: {}, // Optional, value to pass on to [ngClass] on the input field
  19. addStyle: {}, // Optional, value to pass to [ngStyle] on the input field
  20. fieldId: 'datepicker-0', // ID to assign to the input field. Defaults to datepicker-<counter>
  21. useEmptyBarTitle: true, // Defaults to true. If set to false then barTitleIfEmpty will be disregarded and a date will always be shown
  22. };

For available format options check out here.

In case you want to initialize with an empty value, just assign null to the model attribute you’re storing the date and you can customize the message in the bar with the property barTitleIfEmpty.

Locale

To change the locale import it from date-fns. For example import * as frLocale from 'date-fns/locale/fr' and pass it to options options={locale: frLocale}.

To Do

  1. Fix packages vulnerabilities.
  2. Write tests (not a single test has been written yet).
  3. Add ability to add custom class to each calendar component.

Run Included Demo

  1. Clone this repository
  1. git clone https://github.com/martre3/ngx-dates-picker.git
  2. cd ngx-dates-picker
  1. Install packages
  1. npm install
  1. Run Demo
  1. npm start

Licence

MIT