Nimantha Harshana Perera Nimantha Harshana Perera - 6 months ago 195
Javascript Question

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.

Thanks in Advance.

Regards...

Answer

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

Comments