Forked from kpowerinfinity/datetimepicker-ionic.js
Last active
September 19, 2015 08:47
-
-
Save binbin/1a0d14a8cc16d201f694 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//uses angular-bootstrap-datetimepicker: https://github.com/dalelotts/angular-bootstrap-datetimepicker | |
angular.module('mymodule') | |
.directive('myDateTimePicker', function ($ionicPopup) { | |
return { | |
restrict: 'E', | |
template: '<input class="my-date-time-picker" type="text" readonly="readonly" ng-model="formatted_datetime" ng-click="popup()" placeholder="{{placeholder}}">', | |
scope: { | |
'title': '@', | |
'dateModel': '=ngModel', | |
'placeholder': '@' | |
}, | |
controller : function($scope, $filter, $ionicPopup) { | |
$scope.tmp = {}; | |
$scope.tmp.newDate = $scope.dateModel || Date.now(); | |
$scope.onTimeSet = function(newDate, oldDate) { | |
console.log('Selected Date from Old date', oldDate, ' to ', newDate); | |
}; | |
$scope.popup = function() { | |
$ionicPopup.show({ | |
template: '<div class="my-date-time-picker"><datetimepicker data-ng-model="tmp.newDate" data-on-time-set="onTimeSet"></datetimepicker></div>', | |
title: $scope.title, | |
scope: $scope, | |
buttons: [ | |
{text: 'Cancel'}, | |
{ | |
text: '<b>Choose</b>', | |
type: 'button-positive', | |
onTap: function(e) { | |
//$scope.$apply(function() { //error: apply already in progress | |
$scope.dateModel = $scope.tmp.newDate; | |
$scope.formatted_datetime = $filter('date')($scope.tmp.newDate, 'medium'); | |
//}); | |
} | |
} //second button | |
] //buttons array | |
}); //ionicpopup.show | |
}; //scope.popup(); | |
} | |
}; | |
}) | |
//HTML Sample: | |
// <label class="item item-input"> | |
// <span class="input-label">Enter Date</span> | |
// <my-date-time-picker placeholder="Enter Date here" title="Select Date" ng-model="my_model" /> | |
// </label> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment