Event calendar in Angular Material Design

2019-07-09 03:20发布

I want to use Angular Material Design Default Date picker Calendar as a Event Calendar. like: http://prntscr.com/fpg1lw

How can I list my events in calendar? I just want to highlight some specific dates in Angular Material Design Date picker Calendar.

1条回答
Deceive 欺骗
2楼-- · 2019-07-09 03:40

Technically You cannot accomplish this, but using a little trick may work (if you want only to display the events, not to select a date).

According the doc https://material.angularjs.org/latest/api/directive/mdDatepicker , you can use md-date-filter function(Date): boolean / Function expecting a date and returning a boolean whether it can be selected or not.

So you can for example put your date events in an array:

var today = new Date();
today.setHours(0,0,0,0);
var events = [
  today.getTime(),
  today.setDate(today.getDate() - 1),
  today.setDate(today.getDate() - 4)
];
$scope.filter = function(Date) {
  return events.indexOf(Date.getTime()) > -1;
};

And in your html

<md-datepicker ng-model="birthday" md-date-filter="filter" md-is-open="true"></md-datepicker>

You will get all the dates disabled except the dates indicated in your events, then add some style to customize it.

enter image description here

查看更多
登录 后发表回答