luisfarzati / ng-bs-daterangepicker

AngularJS directive for bootstrap-daterangepicker
http://luisfarzati.github.io/ng-bs-daterangepicker/
MIT License
246 stars 167 forks source link

click on apply event #88

Open oriko opened 8 years ago

oriko commented 8 years ago

Hi

Is there a way to trigger event when user click on apply button after selecting dates?

dereklin commented 8 years ago

I am wondering the same

dereklin commented 8 years ago

ng-change works. I had some other issues on the code before...

mlenser commented 8 years ago

autoApply exists in the base version. Should ideally be an option in this as well.

jkernagis2 commented 8 years ago

ng-change does not seem to work correctly, as it gets called twice every time you click Apply. Once when the value of the ng-model is a display string of the date range, and again when it is properly set to the moment.js date objects. Seems like there's possibly some race conditions going on with it as well...

abhishek-g commented 8 years ago

Any Solution Yet, as i have to check for a date object every time.

maruiz93 commented 8 years ago

+1

jangidgirish commented 8 years ago

you can modify directive as per your requirements, basically you want to get default events in controller, i created solution, hope it would be useful

$element.on("apply.daterangepicker", function(ev, picker) {
            if($attributes.dpApply){
               var invoker = $parse($attributes.dpApply);
               invoker($scope, {event: ev, picker: picker});
             }
});

and in view call directive <input class="md-button" type="daterange" ng-model="dates4" ranges="ranges" opens="left" dp-apply="test(event, picker)"/>

in controller

angular.module('App').controller('CtrlName', function ($scope){
  $scope.test = function(ev, picker){
     console.log(ev, picker);
   };
}):

you can also use other events as well, cheers!!!