GVKun编程网logo

angular – MAT_DATE_FORMATS字段的定义/含义(angular datepipe)

7

在这篇文章中,我们将带领您了解angular–MAT_DATE_FORMATS字段的定义/含义的全貌,包括angulardatepipe的相关情况。同时,我们还将为您介绍有关angular–如何为da

在这篇文章中,我们将带领您了解angular – MAT_DATE_FORMATS字段的定义/含义的全貌,包括angular datepipe的相关情况。同时,我们还将为您介绍有关angular – 如何为datepicker实现MD_DATE_FORMATS?、angularjs datetime formate、angularjs – Angular-UI Datepicker:`format-day-header`格式,带有2个字母、angularjs – nggrid单元格模板中的ui-date-format的知识,以帮助您更好地理解这个主题。

本文目录一览:

angular – MAT_DATE_FORMATS字段的定义/含义(angular datepipe)

angular – MAT_DATE_FORMATS字段的定义/含义(angular datepipe)

日期选择器的 customizing-the-parse-and-display-formats的材料示例使用自定义MAT_DATE_FORMATS
export const MY_FORMATS = {
  解析:{
    dateInput:’LL’,
  },
  显示:{
    dateInput:’LL’,
    monthYearLabel:’MMM YYYY’,
    dateA11yLabel:’LL’,
    monthYeara11yLabel:’MMMM YYYY’,
};

我找不到像dateA11yLabel这样的字段将在何处以及如何发挥作用.我能想到的是display.dateInput用于在日历和display上显示所选日期.monthYearLabel用于年份选择器的选择下拉列表.

>其他领域在哪里使用?
>编写自定义MAT_DATE_FORMATS时,必须定义所有
字段?

解决方法

A11Y – 意味着可访问性.看这里 https://material.angular.io/cdk/a11y/overview
在这里 https://material.angular.io/components/datepicker/overview#accessibility

根据我认为这些格式用于在可访问性模式时显示datepicker.

angular – 如何为datepicker实现MD_DATE_FORMATS?

angular – 如何为datepicker实现MD_DATE_FORMATS?

我正在尝试从material2为闪亮的新日期选择器实现我自己的日期格式.根据文档,我必须提供我的MD_DATE_FORMATS版本:
providers: [
  {provide: DateAdapter,useValue: NativeDateAdapter },{provide: MD_DATE_FORMATS,useValue: MY_DATE_FORMATS },],

当我使用默认实现时:

export const MD_NATIVE_DATE_FORMATS: MdDateFormats = {
  parse: {
    dateInput: null,},display: {
    dateInput: {year: 'numeric',month: 'numeric',day: 'numeric'},monthYearLabel: {year: 'numeric',month: 'short'},dateA11yLabel: {year: 'numeric',month: 'long',monthYeara11yLabel: {year: 'numeric',month: 'long'},}
};

我收到日期输入为空的错误.
但它到底是什么类型的?文档说任何.

如果我尝试放置一些虚拟函数,我会收到错误:_dateAdapter.parse不是函数.

function dateinput() {
    return 'ddd';
}
const MY_DATE_FORMATS: MdDateFormats = Object.assign({},MD_NATIVE_DATE_FORMATS,{parse: dateInput });

如何使其工作?

非常感谢推动解决方案的@MariusR.如上所述,您需要提供自己的日期适配器.从plunkr,这很简单如下:
export class OurDateAdapter extends NativeDateAdapter {
  parse(value: any): Date | null {
    if ((typeof value === 'string') && (value.indexOf('/') > -1)) {
      const str = value.split('/');
      return new Date(Number(str[2]),Number(str[1])-1,Number(str[0]),12);
    }
    const timestamp = typeof value === 'number' ? value : Date.parse(value);
    return isNaN(timestamp) ? null : new Date(timestamp);
  }
}

这可以是您的任何TS文件,只需要在组件的模块中使用日期选择器提供:

providers: [
    {provide: DateAdapter,useClass: OurDateAdapter}
  ]

在组件中,您需要在构造函数中使用它:

constructor(private dateAdapter: DateAdapter<Date>) {
    this.dateAdapter.setLocale('en-GB');
  }

可以在这里收集语言环境列表,plunkr示例使用葡萄牙语,我的是英国英语.

http://www.i18nguy.com/unicode/language-identifiers.html

MariusR,鞠躬,为什么官方文档不能有这个?

angularjs datetime formate

angularjs datetime formate

<table><tr>
<td><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49

$filter           showFormat msgDate             msgDate                 NowDate                     msgDate msgDate                     year msgDate.                     month msgDate. parseIntmsgDate. msgDate.                     day msgDate. msgDate. msgDate.                     hour msgDate. msgDate. msgDate.                     minute msgDate. msgDate. msgDate.                     second msgDate. msgDate. msgDate.                     NowYear NowDate.                     NowMonth parseIntNowDate.                     NowDay NowDate.                     NowHour parseIntNowDate.                     NowMinu NowDate.                     NowMill NowDate.                     isHour                 NowHour parseIntmsgDate. minute NowMinu NowHour parseIntmsgDate. isHour NowYear year year month day hour minute                 year NowYear NowMonth month NowDay day month day hour minute                 year NowYear month NowMonth day NowDay isHour                     year NowYear month NowMonth day NowDay isHour                         hour NowHour NowMinu minute                                                             parseIntNowMill parseIntsecond parseIntNowMill parseIntsecond                                                                                                         msg_minu parseInthour parseIntminute                             Now_minu NowHour parseIntNowMinu                         Now_minu msg_minu Now_minu msg_minu Now_minu msg_minu                                                                         time parseIntNowHour hour                 time time parseIntNowHour hour                                           msgDate             angular.sstringmsgDate                 str $filtermsgDate                 showFormatstr                         msgDate            

总结

以上是小编为你收集整理的angularjs datetime formate全部内容。

如果觉得小编网站内容还不错,欢迎将小编网站推荐给好友。

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>
    <divhttps://www.jb51.cc/tag/dis/" target="_blank">display:inline-block; min-height:290px;">
      <datepicker ng-model="dt" format-day-header="EEE" min-date="minDate" show-weeks="true"custom-></datepicker>
    </div>

    <h4>Popup</h4>
    <div>
        <div>
            <p>
              <input type="text"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>
                <button type="button"ng-click="open($event)"><i></i></button>
              </span>
            </p>
        </div>

        <div>
            <p>
              <input type="date"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>
                <button type="button"ng-click="open($event)"><i></i></button>
              </span>
            </p>
        </div>
    </div>
    <div>
        <div>
            <label>Format:</label> <selectng-model="format" ng-options="f for f in formats"><option></option></select>
        </div>
    </div>

    <hr />
    <button type="button"ng-click="today()">Today</button>
    <button type="button"ng-click="dt = '2009-08-24'">2009-08-24</button>
    <button type="button"ng-click="clear()">Clear</button>
    <button type="button"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中定义它你想要的值,但是没有尝试但是应该工作.

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

angularjs – nggrid单元格模板中的ui-date-format

angularjs – nggrid单元格模板中的ui-date-format

我想在我的单元格中使用日期选择器,因此我创建了一个单元格模板

var myDateTemplate= '<input type="text"  ng-model="row.entity.myDate"  />';

我的col模型是

var col = [{
                field : 'myDate',displayName : 'My Date',enableCellEdit : true,width : '130',cellTemplate : myDateTemplate,editableCellTemplate : myDateTemplate,resizable : true,sortable : false
            }]

它工作正常,当我选择日期我得到它的mm / dd / yyyy格式我想将其更改为dd / mm / yyyy格式我添加了ui日期格式

var myDateTemplate = '<input ui-date="{ dateFormat: 'dd mm yyyy' }" ui-date-format="dd mm yyyy" ng-model="row.entity.myDate"/>';

当我使用ui日期格式时,它会抛出一个错误

错误:语法错误:令牌’undefined’不是表达式[{dateFormat:]的列NaN处的主表达式,从[{dateFormat:]开始

而它给出的日期就像

2013年12月23日星期一00:00:00 GMT 0530(印度标准时间)而不是我的优先格式.

解决方法

我认为你很接近,只是绕过日期格式的引号来制作正确的字符串:

var myDateTemplate = '<input ui-date="{ dateFormat: \'dd mm yyyy\' }" ui-date-format="dd mm yyyy" ng-model="row.entity.myDate"/>';

我没有使用完全相同的cellTemplate(大概你的输入字段一旦你逃脱引号就能正常工作).这对我有用:

columnDefs: [{
                field:'StartTime',displayName:'Start Time',cellFilter: 'date:\'MM/dd/yyyy HH:MM:ss\'' 
            },{
                field:'duration',displayName:'Duration'
            },{
                field:'distance',displayName:'distance'
            },{
                field:'typedesc',displayName:'Type'
            },{
                field:'Drivers',displayName:'Drivers'
            }]

关于angular – MAT_DATE_FORMATS字段的定义/含义angular datepipe的问题就给大家分享到这里,感谢你花时间阅读本站内容,更多关于angular – 如何为datepicker实现MD_DATE_FORMATS?、angularjs datetime formate、angularjs – Angular-UI Datepicker:`format-day-header`格式,带有2个字母、angularjs – nggrid单元格模板中的ui-date-format等相关知识的信息别忘了在本站进行查找喔。

本文标签: