Angularjs ng-flatpickr directive scope & binding not working

848 Views Asked by At

I can not pass scope variable to this angularjs directive. The directive (https://github.com/archsaber/angular-flatpickr) defines it scope as:

var ngFlatpickr = angular.module('angular-flatpickr', []);
  ngFlatpickr.directive('ngFlatpickr', [function () {
    return {
      require: 'ngModel',
      restrict: 'A',
      scope: {
        fpOpts: '&',
        fpOnSetup: '&'
      },

I use this directive in my own directive. It is used as follows:

<input ng-flatpickr fp-opts="dateOpts" fp-on-setup="datePostSetup(fpItem)"
       ng-model="myStartDate">

My directive code defines the dateOpts and datePostSetup. My problem is that none of them are called.

function link($scope, element, attrs) {

            $scope.dateOpts = {
                    dateFormat: 'Y-m-d',
                    placeholder: 'Change date..', // Default: 'Select Date..'
                    defaultDate: '2016-03-01 03:30:00 -0300',
                    onChange: function (selectedDates, dateStr, instance) {
                        // Do stuff on change
                    }
                };


            $scope.datePostSetup = function (fpItem) {
                console.log('flatpickr', fpItem);
            }            
0

There are 0 best solutions below