How to catch the bootstrap datepicker change event?

linyuanxie picture linyuanxie · Apr 7, 2015 · Viewed 38.4k times · Source

Now I am trying to do something after user change the date. But seems like my ng-change is ignored.

Here is my code sample:

 <input ng-change='changedate()'
                       type="text" 
                       starting-day="2" 
                       show-button-bar="false" 
                       show-weeks="false" 
                       class="form-control addTicketDateInput" 
                       datepicker-popup="dd MMM" 
                       ng-model="startdate" 
                       is-open="openstart"                         
                       datepicker-options="dateOptions"           
                       ng-required="true"
                       close-text="Close" />

In my controller:

$scope.changedate=function(){
  console.log($scope.startdate);
}

Any idea?

Answer

Michael Tot Korsgaard picture Michael Tot Korsgaard · Feb 3, 2016

You could keep an eye on when the $scope changed.

Something like this:

$scope.startdate;

$scope.$watch("startdate", function(newValue, oldValue) {
    console.log("I've changed : ", startdate);
});