项目作者: nncl

项目描述 :
Custom Datepicker for Angular 8+ applications.
高级语言: TypeScript
项目地址: git://github.com/nncl/ngx-datepicker.git
创建时间: 2019-11-23T17:22:15Z
项目社区:https://github.com/nncl/ngx-datepicker

开源协议:MIT License

下载


Ngxdatepicker

Custom Datepicker for Angular 8+ applications.

npm

Demo.

Getting Started

Install through npm:

  1. npm i @clmeida/ngxdatepicker --save

Include its module in your app.module.ts file:

  1. import { NgxdatepickerModule } from "@clmeida/ngxdatepicker";
  2. @NgModule({
  3. imports: [NgxdatepickerModule],
  4. })
  5. export class AppModule {}

Add the component in your application:

  1. <dd-ngxdatepicker
  2. (dateClicked)="myComponentVariable = $event"
  3. name="date"
  4. [(ngModel)]="date"
  5. ></dd-ngxdatepicker>

It’s not required to use both dateClicked and ngModel together, you can use either one of them.

API

Properties

Name Type Description
invalidDates Array[string] Invalid dates as timestamps
validDates Array[string] Valid dates as timestamps
disablePrevDates Boolean Disable previous dates by today

Example

  1. import { ViewChild } from "@angular/core";
  2. import * as moment from "moment";
  3. export class AppComponent implements OnInit {
  4. invalidDates: string[] = [];
  5. ngOnInit() {
  6. const tomorrow = moment().add(1, 'days').format();
  7. const someDayOfNextMonth = moment().add(1, 'month').format();
  8. this.invalidDates.push(tomorrow);
  9. this.invalidDates.push(someDayOfNextMonth);
  10. }
  11. }
  1. <dd-ngxdatepicker #datepicker
  2. name="date"
  3. [(ngModel)]="date"
  4. [invalidDates]="invalidDates"
  5. [disablePrevDates]="true">
  6. </dd-ngxdatepicker>

Events

Name Description
(dateClicked) Outputs a string when a day is clicked

Methods

Name Description
goPrev Goes back to earlier month
goNext Goes forward to the next month

Example

  1. import { ViewChild } from "@angular/core";
  2. import * as moment from "moment";
  3. export class AppComponent {
  4. @ViewChild("datepicker") datepicker: any;
  5. date: any = moment("25/12/2020", "DD/MM/YYYY").format();
  6. }
  1. <dd-ngxdatepicker #datepicker name="date" [(ngModel)]="date"></dd-ngxdatepicker>
  2. <button type="button" (click)="datepicker?.goPrev()">
  3. My custom prev Button
  4. </button>
  5. <button type="button" (click)="datepicker?.goNext()">
  6. My custom next Button
  7. </button>

Slots

Name Description
prev Replace default prev button with a custom one
next Replace default next button with a custom one
month Replace default month title with a custom one

Example

  1. <dd-ngxdatepicker #datepicker name="date" [(ngModel)]="date">
  2. <button type="button" (click)="datepicker?.goPrev()" prev>Custom Prev</button>
  3. <button type="button" (click)="datepicker?.goNext()" next>Custom Next</button>
  4. <strong month>{{ datepicker.current | date: "MM yyyy" }}</strong>
  5. </dd-ngxdatepicker>

Style

Every time you select a day a class named selected is bound to that element.

I18n

Since this module works with moment.js you can set up its locale globally in your application:

app.module.ts

  1. // ... imports
  2. import * as moment from "moment";
  3. moment.locale("pt-BR");

License

MIT