1.1.3 • Published 6 years ago

ionic2-date-picker v1.1.3

Weekly downloads
19
License
MIT
Repository
github
Last release
6 years ago

Ionic 2 Date Picker

Description

This is a component that shows a date picker to select a date.

AOT

Ionic 2 Date Picker is now AOT Compatibile starting from version 1.1.0. Unfortunately this is a breaking change on previous versions of the DatePicker. The example usage can be in the Getting Started guide.

Preview

preview

Getting Started

Install using npm

$ npm install ionic2-date-picker --save

Add the module DatePickerModule in the app.module.ts

import { NgModule } from '@angular/core';
import { IonicApp, IonicModule } from 'ionic-angular';
import { MyApp } from './app.component';
import { HomePage } from '../pages/home/home';

import { DatePickerModule } from 'ionic2-date-picker';

@NgModule({
  declarations: [
    MyApp,
    HomePage,
  ],
  imports: [
    IonicModule.forRoot(MyApp),
    DatePickerModule
  ],
  bootstrap: [IonicApp],
  entryComponents: [
    MyApp,
    HomePage,
  ],
  providers: [
  ]
})
export class AppModule {}

Import the DatePickerProvider in the page that requires the date picker:

<ion-content padding>
  The world is your oyster.
  <p>
    If you get lost, the <a href="http://ionicframework.com/docs/v2">docs</a> will be your guide.
  </p>
  <button (click)="showCalendar()">Show Calendar</button>
</ion-content>

Inject the DatePickerProvider and ModalController

import { Component } from '@angular/core';

import { ModalController } from 'ionic-angular';

import { DatePickerProvider } from 'ionic2-date-picker';

@Component({
  selector: 'page-home',
  templateUrl: 'home.html',
})
export class HomePage {

  constructor(
    public navCtrl: NavController,
    public modalCtrl: ModalController,
    private datePickerProvider: DatePickerProvider ) {
    
  }

  showCalendar() {
    const dateSelected = 
      this.datePickerProvider.showCalendar(this.modalCtrl);

    dateSelected.subscribe(date => 
      console.log("first date picker: date selected is", date));
  }

  showCalendar2() {
    const dateSelected = 
      this.datePickerProvider.showCalendar(this.modalCtrl);

    dateSelected.subscribe(date => 
      console.log("second date picker: date selected is", date));
  }

}

Date Picker Options

The date picker comes with optional configuration options that can be used on the datePicker.showCalendar(). If you need more options, feel free to leave an issue or submit a pull request ;)

Import the DatePickerOption from the package.

import { DatePickerOption } from 'ionic2-date-picker';

create the datePickerOption and pass it as an argument to the showCalendar() function:

let datePickerOption: DatePickerOption = {
      minimumDate: new Date(), // the minimum date selectable
      maximumDate: new Date(), // the maximum date selectable
      defaultDate: new Date('2020-02-02'),
}; 
this.datePickerProvider.showCalendar(this.modalCtrl, datePickerOption);

Options

PropertyTypeDescription
minimumDateDatethe minimum selectable date
maximumDateDatethe maximum selectable date
defaultDateDatethe default selected date

Contributing

Freely fork and submit a pull request describing what was fixed/added and link it to an issue ;)

1.1.3

6 years ago

1.1.2

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.11

6 years ago

1.0.10

6 years ago

1.0.9

6 years ago

1.0.8

7 years ago

1.0.7

7 years ago

1.0.6

7 years ago

1.0.5

8 years ago

1.0.4

8 years ago

1.0.3

8 years ago

1.0.2

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago