最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How to disable Angular mat-calendar - Stack Overflow

programmeradmin0浏览0评论

I was looking for a way to disable mac-calendar component (not datepicker) in a easy way while I was calling API for data of the selected day.

Found no solution after a lot of search, because there not exists a "disable" property, and the "dateFilter" solution was not good, due to I have also another date filters, what complicates management.

So I ended with this CSS solution

I was looking for a way to disable mac-calendar component (not datepicker) in a easy way while I was calling API for data of the selected day.

Found no solution after a lot of search, because there not exists a "disable" property, and the "dateFilter" solution was not good, due to I have also another date filters, what complicates management.

So I ended with this CSS solution

Share Improve this question asked Feb 3 at 11:31 EagleEagle 1,0741 gold badge15 silver badges27 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

Create a CSS style to emulate disable:

.disabled-calendar {
  pointer-events: none;
  opacity: 0.5;
}

And add the style when waiting for API call:

<mat-calendar
  class="calendar"
  [ngClass]="{ 'disabled-calendar': callingAPI }"
  [maxDate]="maxDate"
  (selectedChange)="dayChange($event)"
  [(selected)]="selectedDate"
></mat-calendar>

Now the calendar is not clicable when I call the API.

dayChange() {
  this.callingAPI = true;
  this.myService.getData().pipe(finalize(() => this.callingAPI = false));
}
发布评论

评论列表(0)

  1. 暂无评论