Timepicker不更新ng-model

时间:2015-04-23 10:05:01

标签: javascript angularjs angularjs-ng-model

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

基本上在控制器中:

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

in 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}} 

1 个答案:

答案 0 :(得分:3)

timepicker将ng-model与元素断开连接,因此不会跟踪更改。

对于一个hacky-solution,你可以在timepicker完成后再次编译元素。

$scope$compile注入您的控制器并致电

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

在元素上调用.timepicker后。

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

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

或者查看http://angular-ui.github.io/bootstrap/#/timepicker以更好地支持角度内的bootstrap-components。