Problem with DatePicker Angularjs

1

Good evening.

I'm using directive to datepicker and I'm getting the following error.

TypeError: Cannot read property 'split' of undefined
at Object.DPGlobal.parseDate (http://localhost:8080/ltfinaceira/assets/js/bootstrap-datepicker.js:393:20)
at Datepicker.update (http://localhost:8080/ltfinaceira/assets/js/bootstrap-datepicker.js:161:25)
at new Datepicker (http://localhost:8080/ltfinaceira/assets/js/bootstrap-datepicker.js:84:8)
at HTMLDivElement.<anonymous> (http://localhost:8080/ltfinaceira/assets/js/bootstrap-datepicker.js:341:38)
at Function.m.extend.each (http://localhost:8080/ltfinaceira/js/Jquery/jquery.min.js:2:2975)
at m.fn.m.each (http://localhost:8080/ltfinaceira/js/Jquery/jquery.min.js:2:835)
at $.fn.datepicker (http://localhost:8080/ltfinaceira/assets/js/bootstrap-datepicker.js:336:15)
at link (http://localhost:8080/ltfinaceira/js/Directive/datepickerDirective.js:6:20)
at invokeLinkFn (http://localhost:8080/ltfinaceira/lib/angular/angular.js:8746:9)
at nodeLinkFn (http://localhost:8080/ltfinaceira/lib/angular/angular.js:8246:11) <div ng-switch="datepickerMode" role="application" ng-keydown="keydown($event)" type="text" class="form-control ng-isolate-scope" ng-model="data" datepicker="">

DIRECTIVE

angular.module('app').directive('datepicker', function() {
return {
    // restrict: 'A',
    require : 'ngModel',
    link: function(scope, element, attrs, ngModelCtrl) {
    $(element).datepicker({
       dateFormat:'dd-mm-yyyy',
       language: 'pt-BR',
       pickTime: false,
       startDate: '01-11-2013',      // set a minimum date
       endDate: '01-11-2030'          // set a maximum date
      }).on('changeDate', function(e) {
        ngModelCtrl.$setViewValue(e.date.toLocaleDateString());
        scope.$apply();
      });
    }
  };
 });
    
asked by anonymous 07.09.2015 / 01:03

1 answer

1

Try to modify the line in the policy that tries to resolve the element,

$(element).datepicker([...]

By

element.datepicker([...]

There is no need to attempt to resolve the element; AngularJS is already passing a direct reference, with a wrapper ready to be consumed.

    
07.09.2015 / 16:31