【问题标题】:Bootstrap DateTimpicker Angular Binding doesn't update after selection in calenderdialog在日历对话框中选择后,Bootstrap DateTipicker Angular Binding 不会更新
【发布时间】:2015-11-25 12:42:26
【问题描述】:

我的引导程序 datetimepicker 的模型绑定有问题,在对话框中选择日期后没有更新。 当我直接编辑输入字段时,会触发绑定,但选择不会更新绑定。

我有一个小 Plunker example

<body ng-controller="MainCtrl">
  <p>Hello {{name}}! {{datum}}</p>
  <div class="input-group">
    <span class="input-group-addon add-on"><span class="fa fa-calendar"></span></span>
    <input type="text" class="form-control datetimepicker" ng-model="datum"/>                                                
  </div>
</body>


var app = angular.module('plunker', []);

app.controller('MainCtrl', function($scope) {
  $scope.name = 'World';
  $scope.datum = new Date();

  if($(".datetimepicker").length > 0){
    $('.datetimepicker').datetimepicker({
      format: 'YYYY-MM-DD HH:mm'
    });            
  }

});

【问题讨论】:

    标签: angularjs datetimepicker model-binding bootstrap-datetimepicker


    【解决方案1】:

    普通引导程序不适用于 Angular。您将需要/应该使用引导角度绑定库而不是引导脚本。您仍然使用引导 css/sass/less 等。Angularstrap 就是这样一个库,它不依赖于 jquery。

    当您使用 angularstraps 日期选择器时,它会更新您的绑定。

    (肮脏、丑陋、混乱)的替代方法是将事件处理程序绑定到引导日期选择器更改事件,并在其中调用$scope.digest() 和/或在文本字段元素上手动触发changed 事件。

    【讨论】:

    • 确实是 datetimepicker 不支持 angular。
    猜你喜欢
    • 1970-01-01
    • 2017-08-17
    • 2015-05-22
    • 2023-03-24
    • 1970-01-01
    • 1970-01-01
    • 2016-12-08
    • 1970-01-01
    • 2023-03-03
    相关资源
    最近更新 更多