fragaria / angular-daterangepicker

Angular.js wrapper for dangrossman/bootstrap-daterangepicker
MIT License
519 stars 372 forks source link

Getting "Cannot read property 'startDate' of null" #236

Closed m4d0 closed 5 years ago

m4d0 commented 7 years ago

Get "TypeError: Cannot read property 'startDate' of null at Array. (angular-daterangepicker.js:93) at Object.ngModelWatch (angular.js:23555) at Scope.$digest (angular.js:14404) at Scope.$apply (angular.js:14675) at done (angular.js:9725) at completeRequest (angular.js:9915) at XMLHttpRequest.requestLoaded (angular.js:9856)" error using the component with formly-form custom template, when the formly directive load the template. The model, initialilly is empty. The error appears on line 93

this is my patch:

       modelCtrl.$formatters.push(function(objValue) {
          var f;
          f = function(date) {
            if (!moment.isMoment(date)) {
              return moment(date).format(opts.locale.format);
            } else {
              return date.format(opts.locale.format);
            }
          };
          // bug fix  -->
          if (objValue) {
                if (opts.singleDatePicker) {
                    return f(objValue);
                } else if (objValue.startDate) {
                    return [f(objValue.startDate), f(objValue.endDate)].join(opts.locale.separator);
                } else {
                    return '';
                }
            } else {
            return '';
          }
        // <---
        });