Closed ranieri82 closed 5 years ago
I'm experiencing the same issue. Let's keep the focus in this ticket as the other one, #87, is a different issue.
@ranieri82 did you find a way around this at all?
Even I faced the picker=undefined
issue, but I was able to get the dates this way :
$scope.datePicker.options = {
eventHandlers: {
'apply.daterangepicker': function(ev, picker) {
$timeout(function(){
console.log($scope.datePicker.date.startDate.format('YYYY-MM-DD'));
console.log($scope.datePicker.date.endDate.format('YYYY-MM-DD'));
});
}
}
}
I also faced with picker=undefined.
Access to date is also available from ev param like this:
$scope.datePicker.options = {
eventHandlers: {
'apply.daterangepicker': function(ev, picker) {
$timeout(function(){
console.log(ev.model.startDate);
console.log(ev.model.endDate);
});
}
}
}
I was struggling with the same issue. As far as I could see, the problem is how the events are delegated. In the current implementation of angular-daterangepicker, event arguments are ignored and the event handlers defined via opts are called using $scope.$evalAsync, which executes the passed function with the current scope as an argument:
for eventType of opts.eventHandlers
el.on eventType, (e) ->
eventName = e.type + '.' + e.namespace
$scope.$evalAsync(opts.eventHandlers[eventName])
Instead, I think the code should look more something like this:
for eventType of opts.eventHandlers
el.on eventType, (e, arg) ->
eventName = e.type + '.' + e.namespace
$scope.$apply(opts.eventHandlers[eventName].call(this, e, arg));
What do you think?
I downloaded the today's version of angular datepicker with BS datepicker v2.1.24. I am also getting the error
Error: picker is undefined
loadConfig/config.eventHandlers["apply.daterangepicker"]
My event handler is like this:
eventHandlers: {
'apply.daterangepicker': function(ev, picker) {
var endDate = picker.endDate.format();
var startDate = picker.startDate.format();
...
}
This issue still exists today.
In the eventHandler for apply.daterangepicker the picker argument is undefined