Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/28.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/cmake/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular mat datepicker仅显示月份和年份_Angular_Material Design_Angular Material_Angular Material2 - Fatal编程技术网

Angular mat datepicker仅显示月份和年份

Angular mat datepicker仅显示月份和年份,angular,material-design,angular-material,angular-material2,Angular,Material Design,Angular Material,Angular Material2,这是我的密码。我用的是有棱角的材料。如何将日历设置为仅显示月份和年份 <input matInput [matDatepicker]="picker" readonly> <mat-datepicker-toggle matSuffix [for]="picker"></mat-datepicker-toggle> <mat-datepicker #picker startView="year" [startAt]="startDate"><

这是我的密码。我用的是有棱角的材料。如何将日历设置为仅显示月份和年份

<input matInput [matDatepicker]="picker" readonly>
<mat-datepicker-toggle matSuffix [for]="picker"></mat-datepicker-toggle>
<mat-datepicker #picker startView="year" [startAt]="startDate"></mat-datepicker>

这项功能似乎最近添加了一个拉取请求

您可以设置视图

this._activeDate = this._monthView ?
this._activeDate = this._currentView == 'month' ?

但是,通过将模式设置为

md-mode="month"
萨吉塔兰

this._activeDate = this._monthView ?
this._activeDate = this._currentView == 'month' ?

如何在angular 5中使用json模式形式的mat datepicker来使用它,对于具有月份和年份的angular Material datepicker--

app.js

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

app.controller('MainCtrl', function($scope) {

  var monthFormat =  buildLocaleProvider("MMM-YYYY");

    function buildLocaleProvider(formatString) {
        return {
            formatDate: function (date) {
                if (date) return moment(date).format(formatString);
                else return null;
            },
            parseDate: function (dateString) {
                if (dateString) {
                    var m = moment(dateString, formatString, true);
                    return m.isValid() ? m.toDate() : new Date(NaN);
                }
                else return null;
            }
        };
    }


  $scope.dateFields = [ 
                {
                    type: 'date',
                    required: false,
                    binding: 'applicant.expectedGraduation',
                    startView: 'month',
                    label: 'Credit Card Expiry - Year/Month picker',
                    mode: 'month',
                    locale: monthFormat
                }
    ];
});
index.html

<!DOCTYPE html>
<html ng-app="plunker">

<head>
  <meta charset="utf-8" />
  <title>AngularJS material-sidenav Plunker</title>
  <script>
    document.write('<base href="' + document.location + '" />');
  </script>
  <link rel="stylesheet" href="https://static.formhero.io/formhero/js/material/v1.1.1-fh-build/angular-material.min.css">
  <link rel="stylesheet" href="style.css" />
  <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.15.1/moment-with-locales.min.js"></script>
  <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular.min.js"></script>
  <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular-animate.min.js"></script>
  <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular-aria.min.js"></script>
  <script src="https://static.formhero.io/formhero/js/material/v1.1.1-fh-build/angular-material.min.js"></script>
  <script src="app.js"></script>
</head>

<body layout="row" layout-wrap flex layout-fill layout-align="start start" ng-controller="MainCtrl">

    <md-input-container flex="100" layout="column">
          <div style="font-size: 10px; color: blue;" label ng-bind="::dateFields[0].label"></div>
          <md-datepicker ng-model="dateFields[0].selectedDate"
                     ng-required="dateFields[0].required"
                     md-date-locale="dateFields[0].locale"
                     md-mode="{{dateFields[0].mode}}"
                     md-open-on-focus="true">
        </md-datepicker>
    </md-input-container>
</body>

</html>

AngularJS材料侧导航插入器
文件。写(“”);
如需演示,请使用下面的链接--

它在最新版本
5.1.0
上发布。请不要使用标签。这是针对React材料的,在这里提供的应该是对其答案的评论,而不是对上述问题的答案。