Code Monkey home page Code Monkey logo

ng2-flatpickr's Introduction

Build Status

ng2-flatpickr

ng2-flatpickr is a lightweight Angular wrapper for flatpickr, which is usable in reactive forms inside Angular.

Examples are here: https://mezoistvan.github.io/ng2-flatpickr-examples/.

npm install --save flatpickr ng2-flatpickr
yarn add flatpickr ng2-flatpickr

For RxJS v5 use ^5.0.2 and for RxJS v6 use ^6.0.2.

Your bundle size will thank you for that.

npm install --save flatpickr [email protected]
yarn add flatpickr [email protected]

OR

npm install --save flatpickr [email protected]
yarn add flatpickr [email protected]

How to use:

Import the Ng2FlatpickrModule to your NgModule:

import { Ng2FlatpickrModule } from 'ng2-flatpickr';

@NgModule({
  imports: [
    Ng2FlatpickrModule
    ...

Example usage in a form component html template:

<ng2-flatpickr formControlName="formControlName"></ng2-flatpickr>

Overwrite the default flatpickr properties by inputting any of the flatpickr options: https://chmln.github.io/flatpickr/options/

import { FlatpickrOptions } from 'ng2-flatpickr';

let exampleOptions: FlatpickrOptions = {
  defaultDate: '2017-03-15'
};

<ng2-flatpickr [config]="exampleOptions" formControlName="formControlName"></ng2-flatpickr>

Add locale to the options

import { FlatpickrOptions } from 'ng2-flatpickr';
import Russian from 'flatpickr/dist/l10n/ru.js';

let exampleOptions: FlatpickrOptions = {
  locale: Russian.ru,
  ...
};

<ng2-flatpickr [config]="exampleOptions" formControlName="formControlName"></ng2-flatpickr>

Set a placeholder for the input:

<ng2-flatpickr placeholder="Pick a date!" formControlName="formControlName"></ng2-flatpickr>

Set a date using a string or a date object:

let randomDateString = '1988-09-19';
let randomDateObject = new Date( 1234567891011 );

<ng2-flatpickr [setDate]="randomDateString" formControlName="formControlName"></ng2-flatpickr>
<ng2-flatpickr [setDate]="randomDateObject" formControlName="formControlName"></ng2-flatpickr>

Flatpickr css needs to be loaded separately. when using @angular/cli, load it in angular-cli.json.

"styles": [
  "../node_modules/flatpickr/dist/flatpickr.min.css"
]

From v6, in angular.json:

"styles": [
  "node_modules/flatpickr/dist/flatpickr.min.css"
]

ng2-flatpickr's People

Contributors

ahmed-anas avatar d42ohpaz avatar dockleryxk avatar linktohack avatar manar-mk avatar mezoistvan avatar murazaki avatar rip3rs avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.