Angularjs   发布时间:2022-04-20  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了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.datetiR_961_11845@E_FORMATs.SHORTDAY.join(‘|’)来提供EEE属性的值.

更好的方法

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

@H_133_6@myApp.config(['$provide',Decorate]); function Decorate($providE) { $provide.decorator('$locale',function ($delegatE) { var value = $delegate.datetiR_961_11845@E_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中定义它你想要的值,但是没有尝试但是应该工作.

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

大佬总结

以上是大佬教程为你收集整理的angularjs – Angular-UI Datepicker:`format-day-header`格式,带有2个字母全部内容,希望文章能够帮你解决angularjs – Angular-UI Datepicker:`format-day-header`格式,带有2个字母所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。