加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

AngularJS 1.3 – Datepicker初始格式不正确

发布时间:2020-12-17 08:23:25 所属栏目:安全 来源:网络整理
导读:我昨天开始使用AngularJS 1.3,我发现一个问题是Datepicker中的初始日期不是定义的格式。日期格式在选择日期后是正确的。 AngularJS 1.2.10的初始格式是正确的,可以通过注释掉脚本标记在示例中看到。 如何将初始格式设置为正确? Plunker example HTML !doc
我昨天开始使用AngularJS 1.3,我发现一个问题是Datepicker中的初始日期不是定义的格式。日期格式在选择日期后是正确的。

AngularJS 1.2.10的初始格式是正确的,可以通过注释掉脚本标记在示例中看到。

如何将初始格式设置为正确?

Plunker example

HTML

<!doctype html>
<html ng-app="plunker">
  <head>
    <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.0-rc.0/angular.min.js"></script>
    <!-- <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.10/angular.js"></script> -->
    <script src="//angular-ui.github.io/bootstrap/ui-bootstrap-tpls-0.11.0.js"></script>
    <script src="example.js"></script>
    <link href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet">
  </head>
  <body>

  <br>
  <br>
  <div ng-controller="DatepickerDemoCtrl">
    <div class="row">
        <div class="col-md-6">
            <p class="input-group">
              <input type="text" class="form-control" datepicker-popup="{{format}}" ng-model="dt" is-open="opened" min-date="minDate" max-date="'2015-06-22'" datepicker-options="dateOptions" date-disabled="disabled(date,mode)" ng-required="true" close-text="Close" />
              <span class="input-group-btn">
                <button type="button" class="btn btn-default" ng-click="open($event)"><i class="glyphicon glyphicon-calendar"></i></button>
              </span>
            </p>
        </div>
    </div>
  </div>
  </body>
</html>

JS

var app = angular.module('plunker',['ui.bootstrap']);
app.controller("DatepickerDemoCtrl",function ($scope) {
  $scope.format = 'dd-MMMM-yyyy';

  $scope.today = function() {
    $scope.dt = new Date();
  };
  $scope.today();

  $scope.open = function($event) {
    $event.preventDefault();
    $event.stopPropagation();

    $scope.opened = true;
  };
});
不确定在1.3中有什么变化,但有一个 bug report for this。

这是在修复问题之前解决问题的初始值的下拉式指令。这里是一个演示Plunker。

angular.module('myApp').directive('datepickerPopup',function (dateFilter,datepickerPopupConfig) {
    return {
        restrict: 'A',priority: 1,require: 'ngModel',link: function(scope,element,attr,ngModel) {
            var dateFormat = attr.datepickerPopup || datepickerPopupConfig.datepickerPopup;
            ngModel.$formatters.push(function (value) {
                return dateFilter(value,dateFormat);
            });
        }
    };
});

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读