0

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);
            }            
Paul
  • 2,474
  • 7
  • 33
  • 48
  • In the example `$ctrl.dateOpts` is an object. In your code it is a function. Why did you make it a function? – georgeawg Jun 09 '19 at 05:42
  • Thanks for pointing out that George. I tried out with a function instead of an object and forgot to revert back to object as I pasted here. I have updated the question to reflect current state of the code. Still neither dateOpts not datePostSetup work. – Paul Jun 09 '19 at 08:51

0 Answers0