Skip to content Skip to sidebar Skip to footer

Angular Material Date Picker Set Only A Particular Day Of Week Selectable (Eg: Monday)

I wonder is there any filtering mechanism for the Angular Material Date Picker, So that I can set only Mondays are selectable from the Date Picker.

Solution 1:

Yes. There is an attribut called md-date-filter which you can use to specify the day you want to be selected by user. In the below example as you are returing return day === 1; It will allow to select mondays only. you can change it from o to 7 as required.

html view file

<md-datepicker ng-model="myDate" md-placeholder="Enter date" md-date-filter="onlyMonday">
</md-datepicker>

In Controller File

$scope.onlyMonday = function(date) {
                          var day = date.getDay();
                          return day === 1;
}

http://codepen.io/next1/pen/EKmdPx


Solution 2:

Take a look at this. It defaults to next monday on datepicker.

$scope.today = new Date('05/30/2016');
$scope.nextMonday = $scope.today;
daystoAdd = 7 - ($scope.today.getDay()) + 1;
$scope.nextMonday.setDate($scope.today.getDate() + daystoAdd);

Post a Comment for "Angular Material Date Picker Set Only A Particular Day Of Week Selectable (Eg: Monday)"