Date Picker for Ionic

Hello All,
Thank you for your help.
I have installed plugin, then copied file DatePicker.js (from WWW/Android) in my project JS folder and then used above code to invoke DatePicker.
However that result in exception mentioned as below
Uncaught ReferenceError: module is not defined
ReferenceError: cordova is not defined
at (http://localhost:8100/js/DatePicker.js:51:2)
at Scope.$scope.showDatePicker (http://localhost:8100/js/Controller/hodgkin.js:48:20)
at Parser.functionCall (http://localhost:8100/lib/ionic/js/ionic.bundle.js:18471:21)
at http://localhost:8100/lib/ionic/js/ionic.bundle.js:43026:9
at Scope.$get.Scope.$eval (http://localhost:8100/lib/ionic/js/ionic.bundle.js:20326:28)
at Scope.$get.Scope.$apply (http://localhost:8100/lib/ionic/js/ionic.bundle.js:20424:23)
at HTMLInputElement. (http://localhost:8100/lib/ionic/js/ionic.bundle.js:43025:13)
at http://localhost:8100/lib/ionic/js/ionic.bundle.js:10478:10
at forEach (http://localhost:8100/lib/ionic/js/ionic.bundle.js:7950:18)
at HTMLInputElement.eventHandler (http://localhost:8100/lib/ionic/js/ionic.bundle.js:10477:5)
on investigating the code on line 60 of DatePicker.js.
module.exports = datePicker;

I am invoking this in input type=text and ng-click=“showDatePicker()”

Please let me know if I am doing anything wrong


you don’t need to include DatePicker.js in your code. Try removing it.

You can only test this plugin in a native application, in your browser, phonegep plugins won’t have any effect :wink: Try testing in emulator or on device!

1 Like

You can take a look at this post for date-picker also vali in browser for test

Thanks all, Indeed date picker only works in emulator. Need to check feasibility of the same.


Hi @saurabhgupta050, I have created both time picker and date picker for ionic frame works.
Please have a look at the below links.

ionic-timepicker demo

ionic-timepicker Bower component

ionic-datepicker demo

ionic-datepicker Bower component


How I can make update simultaneously for title in header with format date time after selected date with your script?
Its my example html template for title:

<ion-view cache-view="false" title="{{ currentDate | date:'MMM  dd, yyyy' }}">

Thanks before!

In call back function you will get the complete date object. You can use that date and you can assign it to some variable(lets say updatedDate), then you can use similar to what you have used <ion-view cache-view="false" title="{{ updatedDate | date:'MMM dd, yyyy' }}">. I think this should work.

I have released a new version of ionic-datepicker i.e. v0.8.0. If you wish to use this plug-in, please use this updated version to get the latest features and few bug fixes.

Hi rajesh,
could u tell how to view the saved local storage date in datepicker? and also how to view the stored time in timepicker?

@praveenjp, Please follow the instructions mentioned here. It explains your query i guess.

Thanks for your response,

<ionic-datepicker input-obj="datepickerObject">
  <button class="button button-block button-positive"> {{datepickerObject.inputDate | date:'dd - MMMM - yyyy'}}</button>

That above code shows the current date…but i want to show my localstorage date on it…for example i get the date form localstorage and use this code {{}} to view in datepicker.

please help me to find out the actual solution.

You have to get the date from LocalStorage, when you enter into the page where you are using this component. As the page will have a separate controller, on entering into that controller you can get it from LocalStorage and in the same controller you might be using the object which is needed for this component. To that object you can assign the date which you have already got from the LocalStorage.

Thank You… It’s works fine but i got one small issue… when i changed the date it’s shows the same date in ionic-datepicker

You have to assign the date to $scope.datepickerObject.inputDate, which you will receive in the callback. Then it will also update the date on the button where you are using it. If you wish to continue this discussion on ionic-datepicker component, you can continue here. That will also help people who are using this component.

Thank You @rajeshwarpatlolla !.. It’s works fine… :relaxed:

hi @rajeshwarpatlolla the date in the button still not changing when i set a date. please help

You need to assign the date to a scope variable in the controller. This is the variable, which you need use to show the date on the button.

it’s so simple just use input type= date it will give 100% effect of the date picker.
and in angular you can use max and min date validation also.

I could not make your plugin work for me.
I always have the error: ionicDatePickerProvider does not exist

After injecting in the main module and trying to configure in the .config(…) method.

I just gave up on using it, after several tries I could not find out what’s wrong.