angular-bootstrap-datetimepicker-directive icon indicating copy to clipboard operation
angular-bootstrap-datetimepicker-directive copied to clipboard

$element.on(...).datetimepicker is not a function

Open dotku opened this issue 10 years ago • 4 comments

I newly donwload and after bower, I got this error~

dotku avatar Dec 15 '15 07:12 dotku

I have the problem too. A workaround is you should load jquery before angular.

fstronin avatar Dec 20 '15 08:12 fstronin

Quickfix: wrap the $element usage in the datetimepicker directive with jQuery's $(...) function:

  .directive('datetimepicker', [
    '$timeout',
    'datetimepicker',
    function ($timeout,
              datetimepicker) {

      var default_options = datetimepicker.getOptions();

      return {
        require : '?ngModel',
        restrict: 'AE',
        scope   : {
          datetimepickerOptions: '@'
        },
        link    : function ($scope, $element, $attrs, ngModelCtrl) {
          var passed_in_options = $scope.$eval($attrs.datetimepickerOptions);
          var options = jQuery.extend({}, default_options, passed_in_options);


          // @schakko: fix #23 https://github.com/diosney/angular-bootstrap-datetimepicker-directive/issues/23 
          $($element)
            .on('dp.change', function (e) {
              if (ngModelCtrl) {
                $timeout(function () {
                  ngModelCtrl.$setViewValue(e.target.value);
                });
              }
            })
            .datetimepicker(options);

          function setPickerValue() {
            var date = null;

            if (ngModelCtrl && ngModelCtrl.$viewValue) {
              date = ngModelCtrl.$viewValue;
            }

            // @schakko: fix #23 https://github.com/diosney/angular-bootstrap-datetimepicker-directive/issues/23 
            $($element)
              .data('DateTimePicker')
              .date(date);
          }

          if (ngModelCtrl) {
            ngModelCtrl.$render = function () {
              setPickerValue();
            };
          }

          setPickerValue();
        }
      };
    }
  ]);

schakko avatar Jan 15 '16 15:01 schakko

Any update on this? the workaround is not working for me, it is mandatory to load bootstrap.min.css?

lgarest avatar Jun 03 '16 15:06 lgarest

@schakko thanks for your fix !! It works well !

Lilipi avatar Nov 13 '18 09:11 Lilipi