Timepicker 不按模型更新

Timepicker not updating ng-model

我在某些输入上使用时间选择器,时间选择器不更新 ng-模型,我做了一个 plunker

基本上在控制器中:

$('.TimePickers').timepicker();

在html中:

<div class="input-group bootstrap-timepicker">
  <input  ng-model="MonOpen" id="" type="text" class="input-small TimePickers">
  <span class="input-group-addon"><i class="glyphicon glyphicon-time"></i></span>
</div>
Model which in not updating: {{MonOpen}} 

时间选择器将 ng-model 与您的元素断开连接,因此不会跟踪更改。

对于 hacky 解决方案,您可以在时间选择器处理完之后再次 $compile 元素。

$scope$compile 注入您的控制器并调用

$compile($('.TimePickers'))($scope)

在元素上调用 .timepicker 之后。

  app.controller('TimeController', function($compile, $scope){

            $('.TimePickers').timepicker();
            $compile($('.TimePickers'))($scope)
  });

或者查看 http://angular-ui.github.io/bootstrap/#/timepicker 以更好地支持 angular 中的 bootstrap-组件。