angularjs – Angular-UI Datepicker:`format-day-header`格式,带有2个字母

前端之家收集整理的这篇文章主要介绍了angularjs – Angular-UI Datepicker:`format-day-header`格式,带有2个字母前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试使用2个字母显示带有日标题(星期标题中的日期格式)的角度ui datepicker
3个字母的defualt由attr format-day-header =“EEE”定义
我在哪里可以找到2个字母的选项?
(我试过’EE’它只是在标题中写EE).

吸管是plunker link

angular.module('ui.bootstrap.demo',['ngAnimate','ui.bootstrap']);
angular.module('ui.bootstrap.demo').controller('DatepickerDemoCtrl',function ($scope) {
  $scope.today = function() {
    $scope.dt = new Date();
  };
  $scope.today();

  $scope.clear = function () {
    $scope.dt = null;
  };

  // Disable weekend selection
  $scope.disabled = function(date,mode) {
    return ( mode === 'day' && ( date.getDay() === 0 || date.getDay() === 6 ) );
  };

  $scope.toggleMin = function() {
    $scope.minDate = $scope.minDate ? null : new Date();
  };
  $scope.toggleMin();

  $scope.open = function($event) {
    $scope.status.opened = true;
  };

  $scope.dateOptions = {
    formatYear: 'yy',startingDay: 1
  };

  $scope.formats = ['dd-MMMM-yyyy','yyyy/MM/dd','dd.MM.yyyy','shortDate'];
  $scope.format = $scope.formats[0];

  $scope.status = {
    opened: false
  };

  var tomorrow = new Date();
  tomorrow.setDate(tomorrow.getDate() + 1);
  var afterTomorrow = new Date();
  afterTomorrow.setDate(tomorrow.getDate() + 2);
  $scope.events =
    [
      {
        date: tomorrow,status: 'full'
      },{
        date: afterTomorrow,status: 'partially'
      }
    ];

  $scope.getDayClass = function(date,mode) {
    if (mode === 'day') {
      var daytocheck = new Date(date).setHours(0,0);

      for (var i=0;i<$scope.events.length;i++){
        var currentDay = new Date($scope.events[i].date).setHours(0,0);

        if (daytocheck === currentDay) {
          return $scope.events[i].status;
        }
      }
    }

    return '';
  };
});
<!doctype html>
<html ng-app="ui.bootstrap.demo">
  <head>
    <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.4.3/angular.js"></script>
    <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.4.3/angular-animate.js"></script>
    <script src="//angular-ui.github.io/bootstrap/ui-bootstrap-tpls-0.13.3.js"></script>
    <script src="example.js"></script>
    <link href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet">
  </head>
  <body>

<style>
  .full button span {
    background-color: limegreen;
    border-radius: 32px;
    color: black;
  }
  .partially button span {
    background-color: orange;
    border-radius: 32px;
    color: black;
  }
</style>
<div ng-controller="DatepickerDemoCtrl">
    <pre>Selected date is: <em>{{dt | date:'fullDate' }}</em></pre>

    <h4>Inline</h4>
    <div style="display:inline-block; min-height:290px;">
      <datepicker ng-model="dt" format-day-header="EEE" min-date="minDate" show-weeks="true" class="well well-sm" custom-class="getDayClass(date,mode)"></datepicker>
    </div>

    <h4>Popup</h4>
    <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="status.opened" min-date="minDate" max-date="'2020-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 class="col-md-6">
            <p class="input-group">
              <input type="date" class="form-control" datepicker-popup ng-model="dt" is-open="status.opened" min-date="minDate" max-date="'2020-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 class="row">
        <div class="col-md-6">
            <label>Format:</label> <select class="form-control" ng-model="format" ng-options="f for f in formats"><option></option></select>
        </div>
    </div>

    <hr />
    <button type="button" class="btn btn-sm btn-info" ng-click="today()">Today</button>
    <button type="button" class="btn btn-sm btn-default" ng-click="dt = '2009-08-24'">2009-08-24</button>
    <button type="button" class="btn btn-sm btn-danger" ng-click="clear()">Clear</button>
    <button type="button" class="btn btn-sm btn-default" ng-click="toggleMin()" tooltip="After today restriction">Min date</button>
</div>
  </body>
</html>
我遇到了同样的问题,在ui-bootstrap.js / ui-bootstrap-tpls.js文件搜索了EEE,他们正在使用正则表达式:$locale.DATETIME_FORMATS.SHORTDAY.join(‘|’)来提供EEE属性的值.

更好的方法

使用$provide.decorator更新provider $locale的SHORTDAY

myApp.config(['$provide',Decorate]);
function Decorate($provide) {
  $provide.decorator('$locale',function ($delegate) {
    var value = $delegate.DATETIME_FORMATS;

    value.SHORTDAY = [
        "Su","Mo","Tu","We","Th","Fr","Sa"
    ];

    return $delegate;
  });
};

写了这篇文章Customizing Angular-UI Bootstrap’ Directives,以获得您可能想要做的更多自定义.

另一种方式

您必须在angular.js中搜索您正在使用的SHORTDAY,并根据您的需要进行编辑.

例如:

"SHORTDAY": [
  "Su","Sa"
],

这应该工作:)

你也可以创建一个新的EE关联(在ui-bootstrap或ui-bootstrap-tpls中),并在Angular.js中定义它你想要的值,但是没有尝试但是应该工作.

告诉我是否有更好的方法.

原文链接:https://www.f2er.com/angularjs/140318.html

猜你在找的Angularjs相关文章