Angular Material Date Picker Set Only a Particular Day of Week Selectable (Eg: Monday)

走远了吗. 提交于 2019-12-13 02:11:59

问题


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...


回答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




回答2:


@Nimantha - 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);


来源:https://stackoverflow.com/questions/36198626/angular-material-date-picker-set-only-a-particular-day-of-week-selectable-eg-m

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!