ng-bs-daterangepicker icon indicating copy to clipboard operation
ng-bs-daterangepicker copied to clipboard

$element.data('daterangepicker').startDate throwing Cannot read property 'startDate ' of undefined

Open stacey-david opened this issue 10 years ago • 14 comments

When the page has loaded the line $element.data('daterangepicker').startDate within the $scope.$watch statement is throwing a "Cannot read property 'startDate ' of undefined" error.

Has anyone seen this error before or have an idea what might be causing it?

stacey-david avatar Jun 17 '14 11:06 stacey-david

I just tried to use this directive and I got this error. Don't know where it come from now but I'm looking to it.

I'm using angular 1.3.0 beta14.

maxailloud avatar Jul 07 '14 08:07 maxailloud

Hi @maxailloud

Have you had any look figuring out what is causing the issue?

stacey-david avatar Jul 18 '14 10:07 stacey-david

Unfortunately no. And I had to change directive because of library already used in my project. So I didn't investigate further.

maxailloud avatar Jul 18 '14 11:07 maxailloud

I got the same issue. The issue was related to overwritting of the $el value. Script loading order fixed this one.

Durairaj avatar Aug 27 '14 15:08 Durairaj

I am getting this issue as well.

Progdom avatar Jan 05 '15 22:01 Progdom

Had the same issue I forgot to add

<script type="text/javascript" src="daterangepicker.js"></script>

So your full imports should be:

<link rel="stylesheet" type="text/css" href="bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="daterangepicker-bs3.css">
<script type="text/javascript" src="jquery.min.js"></script>
<script type="text/javascript" src="bootstrap.min.js"></script>
<script type="text/javascript" src="moment.min.js"></script>
<script type="text/javascript" src="daterangepicker.js"></script>
<script type="text/javascript" src="angular.min.js"></script>
<script type="text/javascript" src="ng-bs-daterangepicker.js"></script>

Double check to make sure you have all of these in your html. Some of them are not located in this repo such as daterangepicker-bs3.css and daterangepicker.js. You will have to grab those from the original non-angular version of this repo

jpetraws avatar Jan 06 '15 16:01 jpetraws

@stacey-david @maxailloud @Progdom are you still getting this error?

alanjames1987 avatar Jul 23 '15 19:07 alanjames1987

Don't use it anymore so I can't answer to that.

maxailloud avatar Jul 29 '15 12:07 maxailloud

Still have the issue. The only "easy" fix is to set a date to the scope in controller. Passing a undefined value of ngModel throw the "TypeError: Cannot read property 'startDate' of .."

mbret avatar Sep 18 '16 22:09 mbret

+1

Having the same issue here...

aevo-tech avatar Nov 19 '16 20:11 aevo-tech

bs-daterangepicker needs startDate as compulsory parameter to be passed on initialization. You should pass at least null to leave it blank or any date object. for ex. $scope.profile.birthday = {startDate: null}

nirav2410 avatar Dec 19 '16 08:12 nirav2410

This issue still exist.

rajendrattnd avatar Jul 31 '17 17:07 rajendrattnd

This issue still exist.

ZAKRUTKA avatar Nov 28 '17 14:11 ZAKRUTKA

call this function to make this work.

function CallDateRange(){
  var start = moment();
  var end = moment();

  function cb1(start, end) {
    $('._dateRange span').html(start.format('MMMM D, YYYY') + ' - ' + end.format('MMMM D, YYYY'));
  }

  $('._dateRange').daterangepicker({
    startDate: start,
    endDate: end,
		opens: "left",
    ranges: {
      'Today': [moment(), moment()],
      'Yesterday': [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
      'Last 7 Days': [moment().subtract(6, 'days'), moment()],
      'Last 30 Days': [moment().subtract(29, 'days'), moment()],
      'This Month': [moment().startOf('month'), moment().endOf('month')],
      'Last Month': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')]
    }
  }, cb1);
}
CallDateRange();
		
var startDate   =  $("._dateRange").data('daterangepicker').startDate.format("YYYY-MM-DD");
var endDate     =  $("._dateRange").data('daterangepicker').endDate.format("YYYY-MM-DD");

yusoph-dev avatar Mar 08 '18 07:03 yusoph-dev