Code Monkey home page Code Monkey logo

ng2-datepicker's Introduction

ng2-datepicker

Angular2 Datepicker Component

ng2-datepicker is a datepicker component for Angular2.

Demo

http://ng2-datepicker.jankuri.com

Installation:

Install ng2-datepicker via npm

npm install ng2-datepicker --save

Then include Ionicons's CSS in index.html

<link rel="stylesheet" href="http://code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css" media="all">

Usage

Usage examples are based on a project created with Angular CLI + Angular 2.0.0+

Option A: Using ng2-datepicker with ngModel

  1. Import DatePickerModule in app.module.ts
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';

import { DatePickerModule } from 'ng2-datepicker';

import { AppComponent } from './app.component';

@NgModule({
  declarations: [
    Appcomponent
  ],
  imports: [
    BrowserModule,
    FormsModule,
    HttpModule,
    DatePickerModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule {}
  1. Use <ng2-datepicker> in app.component.html
<ng2-datepicker [(ngModel)]="date"></ng2-datepicker>

Selected date is: {{ date }}

Option B: Using ng2-datepicker with FormBuilder (ReactiveFormsModule)

  1. Import DatePickerModule and ReactiveFormsModule in app.module.ts
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';
import { DatePickerModule } from 'ng2-datepicker';

import { AppComponent } from './app.component';

@NgModule({
  declarations: [
    Appcomponent
  ],
  imports: [
    BrowserModule,
    FormsModule,
    HttpModule,
    ReactiveFormsModule,
    DatePickerModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule {}
  1. Create FormControl for date field in app.component.ts
import { Component, OnInit } from '@angular/core';
import { FormGroup, FormBuilder } from '@angular/forms';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit {

  dataForm: FormGroup;

  constructor(private formBuilder: FormBuilder) {
  }

  ngOnInit() {
    this.dataForm = this.formBuilder.group({
      date: ''
    });  
  }
}
  1. Use <ng2-datepicker> with formControlName in app.component.html
<form [formGroup]="dataForm">
  <ng2-datepicker formControlName="date"></ng2-datepicker>
</form>

API

Options can be passed to <ng2-datepicker> component via property bindings.

Property Type Required Default Description
class string No '' CSS class name(s) to apply to datepicker's container
opened boolean No false Set to true to open the calendar by default
format string No YYYY-MM-DD Date format of the calendar. This will be bound to the model as the date's value.
viewFormat string No D MMMM YYYY Date format to display in the view.
firstWeekdaySunday boolean No false Set to true to set first day of the week in calendar to Sunday instead of Monday.

Example from demo:

<ng2-datepicker [(ngModel)]="data.date"></ng2-datepicker>
<ng2-datepicker [(ngModel)]="data2.date" class="danger"></ng2-datepicker>
<ng2-datepicker [(ngModel)]="data3.date" class="success"></ng2-datepicker>
<ng2-datepicker [(ngModel)]="data4.date" class="warning"></ng2-datepicker>

Licence

This project is licensed under the MIT license. See the LICENSE file for more info.

ng2-datepicker's People

Contributors

armno avatar artmickiewicz avatar edimitchel avatar gaaamii avatar jkuri avatar matjanos avatar mkreis avatar piizei avatar poke avatar ranakrunal9 avatar richard87 avatar tauqeer81 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.