在日期选择angular-ui bootstrap上添加click事件

时间:2016-05-14 04:12:08

标签: angularjs angular-ui-bootstrap bootstrap-datepicker

每当用户在angular-ui datetimepicker中选择日期时,我都想执行一些操作。

    <input type="text" class="form-control" 
        uib-datepicker-popup="{{dashctrl.format}}" 
        ng-model="dashctrl.checkOutDtDashboard" 
        is-open="dashctrl.popup2.opened" 
        datepicker-options="dashctrl.dateOptionsCheckOut" 
        ng-required="true" 
        close-text="Close" 
        alt-input-formats="dashctrl.altInputFormats" />

控制器类似于:DashController as dashctrl

在我的日历退出的相关控制器中,有我可以选择的日期,并且发布日期选择,我想执行一些操作。

已经在库中的日期选择中编写了select(dt.date)方法,但如何在我的控制器中使用它。

我尝试使用

  1. $rootScope.select
  2. $scope.select
  3. 但这些在我的代码中无效。

2 个答案:

答案 0 :(得分:3)

您可以对输入进行ng-change并将其映射到控制器上的某个功能。用户在日期选择器中选择日期后,将触发此操作。这听起来并不像你试图覆盖日期选择器选择的功能,所以我认为这应该有效。

答案 1 :(得分:0)

$watch控制器的日期选择器ng-model中注册DashController

$scope.$watch('checkOutDtDashboard', function(newDate) {
    if (newDate) {
        console.log("Got the new date", newDate, "or", $scope.checkOutDtDashboard);
    }
});