Angular Material Date Picker Set Only a Particular

2019-08-13 15:13发布

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

2条回答
老娘就宠你
2楼-- · 2019-08-13 15:37

@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);
查看更多
放我归山
3楼-- · 2019-08-13 15:49

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

查看更多
登录 后发表回答