Ui.bootstrap.datepicker Clear button event

Currently using https://angular-ui.github.io/bootstrap/#/datepicker

How can I connect a clear button so that when I click it I can be notified?

I like something like this, when Click the Clear button, change the value of the textbox.

+3


source to share


3 answers


How about if you use $ watch on the model that the date is bound to?

$scope.$watch('dt', function(){
    //do something
});

      



Because after the Reset button is clicked it will affect the model.

+2


source


Have you tried looking at the "edit in plunkr" link you provided? The code is very simple ...

Html

<datepicker ng-model="dt"></datepicker>
<button type="button" ng-click="clear()">Clear</button>

      



Js

$scope.clear = function () {
    $scope.dt = null;
    // do something else...
};

      

0


source


Following the above answer, you may find that Clear was clicked with $scope.$watch

like this:

$scope.$watch('dt', function(newValue, oldValue) {
   if (newValue=== null) {
      // Clear has been clicked
   }
});

      

0


source







All Articles