I am working on a project and I have a md-datepicker on it and I want this md-datepicker to show only the months of the year(January, February, and so on ......). How can I do this?
Here is my code so far:
HTML
<md-datepicker ng-model="currentDate" md-current-view="month" md-date-filter="monthlyDate"></md-datepicker>
JS
var app = angular.module("DashboardApp", ['ngMaterial', 'ngAnimate','md.data.table']);
app.controller('rptController', ['$scope', function ($scope) {
$scope.currentDate = new Date();
$scope.monthlyDate = new Date($scope.currentDate.getMonth('MM'))}]);
It sounds like you want an md-select rather than a md-datepicker. See example below.
(function() {
angular
.module('exampleApp', ['ngAnimate', 'ngAria', 'ngMaterial'])
.controller('ExampleController', ExampleController);
function ExampleController() {
var vm = this;
vm.monthNames = ["January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"
];
}
ExampleController.$inject = [];
})();
<!DOCTYPE html>
<html ng-app='exampleApp'>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.5/angular.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.5/angular-animate.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.5/angular-aria.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/angular-material/1.0.9/angular-material.min.css">
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/angular-material/1.0.9/angular-material.min.js"></script>
</head>
<body ng-controller="ExampleController as vm">
<md-input-container>
<md-select ng-model="vm.chosenMonth" placeholder="Select a month">
<md-option ng-value="month" ng-repeat="month in vm.monthNames">{{ month }}</md-option>
</md-select>
</md-input-container>
</body>
</html>
This is possible with the datepicker, with the latest version. You can set md-mode="month"
working demo below
<md-input-container flex="100" layout="column">
<div style="font-size: 10px; color: blue;" label ng-bind="::dateFields[2].label"></div>
<md-datepicker ng-model="dateFields.selectedDate"
ng-required="dateFields.required"
md-date-locale="dateFields.locale"
md-mode="month"
md-open-on-focus="true">
</md-datepicker>
</md-input-container>
DEMO