An angular directive to use flatpickr. Currently it has following capabilities
fp-opts
attributefp-on-setup
attribute to get the created flatpickr objectThere are now support for a directive based approach and a component based
Installnpm install -S angular-flatpickr
node_modules/angular-flatpickr/dist/ng-flatpickr-comp.js
node_modules/angular-flatpickr/dist/ng-flatpickr.js
angular-flatpickr
module in your app as shownExample as Componentvar module = angular.module('atApp.somemodule', [
  'angular-flatpickr'Â
]);
2 ways to use the component, first is just stating the ng-flatpickrctrl.dateOpts = {
  dateFormat: 'Y-m-d',
  placeholder: 'Change date..',Â
  defaultDate: '2016-03-01 03:30:00 -0300',
  onChange: function(selectedDates, dateStr, instance) {
   Â
  }
};
Â
ctrl.datePostSetup = function(fpItem) {
  console.log('flatpickr', fpItem);
}
The other way is if you want to set a placeholder or do something in the inside element you can use it like this<ng-flatpickr
  fp-opts="$ctrl.dateOpts"
  fp-on-setup="$ctrl.datePostSetup({
    fpItem: fpItem
  })">
</ng-flatpickr>
If ng-model is stated it will set the initial date to match it<ng-flatpickr
  fp-opts="$ctrl.dateOpts"
  fp-on-setup="$ctrl.datePostSetup({
    fpItem: fpItem
  })">
</ng-flatpickr>
Example as Directive<ng-flatpickr
  ng-model="'28-10-2018'"
  fp-opts="$ctrl.dateOpts"
  fp-on-setup="$ctrl.datePostSetup({
    fpItem: fpItem
  })">
</ng-flatpickr>
$scope.dateOpts = {
  dateFormat: 'Y-m-d',
  placeholder: 'Change date..',Â
  defaultDate: '2016-03-01 03:30:00 -0300',
  onChange: function(selectedDates, dateStr, instance){
   Â
  }
};
Â
$scope.datePostSetup = function(fpItem) {
  console.log('flatpickr', fpItem);
}
<div ng-repeat="date in dates">
  <input
    ng-flatpickr
    fp-opts="dateOpts"
    fp-on-setup="datePostSetup(fpItem)"
    ng-model="date.selectedDateObj"
    data-enabletime="true">
</div>
Note: This directive doesn't watch over the fp-opts
values. For doing any changes to the flatpickr element created, use object returned from the on-setup callback
angular-flatpickr module is under MIT license see project root
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4