fragaria / angular-daterangepicker

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

'apply.daterangepicker' event callback receives incorrect arguments #187

Closed EoinGriffin-AI closed 5 years ago

EoinGriffin-AI commented 8 years ago

https://github.com/fragaria/angular-daterangepicker#advanced-usage

The arguments for the callback function are expected to be function(ev, picker) { ... } based on the documentation above. Those would be helpful arguments because then we can inspect the picker and/or the html element to get the current values for startDate and endDate (so that I can do something like this 'initially empty' example here: http://www.daterangepicker.com/#ex5)

BUT what we actually get is a scope object (not helpful because the initial startDate and endDate aren't stored there), so there's no reference to the element or the daterangepicker data. Therefore we must use jQuery, or make another directive, just to access that element and get its data.

jQuery's not a good option because it's easily mis-used. We must be sure not to accidentally target the wrong daterangepicker. Writing another directive is what I ended up doing but it's a hacky solution and wouldn't be needed if the arguments were as described in the docs.

fghamsary commented 8 years ago

The way to resolve this issue in the code is that on line 149 you have to change to the following code: return $scope.$evalAsync(function() { return $parse(opts.eventHandlers[eventName])(e, picker) }); I'll make a pull request for it. And of course on the two lines before, while binding the event we should get the second argument.