问题描述
我使用AngularJS TimePicker(ui.bootstrap.timepicker)。当timepicker更改时,我想启动一个事件。我寻找一个ng-change属性,但没有找到一个。
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.
我的目的是保存对模型所做的更改,当时间改变了现在我使用ng-model来设置模型,但是我不知道如何通知控制器,以便它可以执行保存(该模型被序列化为本地存储)。我想避免使用保存按钮,如果可能的话。
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.
在相关的笔记中,我也想为ui.bootstrap做同样的事情。 datePicker。
On a related note, I would also like to do the same thing for ui.bootstrap.datepicker.
推荐答案
您可以使用$ scope. $ watch来监听timepicker(或datepicker)的更改,并调用任何需要在控制器。这是一个基于引导示例的,但在时间更改时提醒。您应该也可以为datepicker应用类似的逻辑。
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.
这篇关于anglejs timepicker ng-change的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!