angularjs timepicker ng-change

Josh Petitt picture Josh Petitt · Jul 21, 2013 · Viewed 16.2k times · Source

I am using AngularJS TimePicker (ui.bootstrap.timepicker). I would like to fire an event when the timepicker is changed. I looked for an ng-change attribute, but did not find one.

My purpose is that I would like to save the changes that are made to the model when the time is changed. Right now I've used ng-model to set the model, but I cannot figure out how to notify the controller so it can perform the save (the model is serialized to localstorage). I would like to avoid the use of a "Save" button if possible.

On a related note, I would also like to do the same thing for ui.bootstrap.datepicker.

Answer

rajasaur picture rajasaur · Jul 21, 2013

You could use $scope.$watch to listen for changes to the timepicker (or datepicker) and call whatever is needed in the Controller. Here is a plunker that is based on the bootstrap example but alerts whenever the time is changed. You should be able to apply a similar logic for datepicker as well.