Angular Material Date Picker仅设置一周中的特定一天(例如:星期一) [英] Angular Material Date Picker Set Only a Particular Day of Week Selectable (Eg: Monday)

查看:144
本文介绍了Angular Material Date Picker仅设置一周中的特定一天(例如:星期一)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道Angular Material Date Picker是否有任何过滤机制,以便我只能设置从Date Picker中选择星期一的时间.

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.

预先感谢.

关于...

推荐答案

是.有一个名为md-date-filter的属性,您可以使用该属性指定用户要选择的日期.在下面的示例中,当您重试return day === 1;时,它将仅选择星期一.您可以根据需要将其从o更改为7.

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查看文件

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

在控制器文件中

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

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

这篇关于Angular Material Date Picker仅设置一周中的特定一天(例如:星期一)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆