简体   繁体   English

Angular Calendar - 如何使用动态 beforeMonthViewRender

[英]Angular Calendar - How to use Dynamic beforeMonthViewRender

I'm trying create a attendance calendar and i have to change column color based on leave types.我正在尝试创建一个考勤日历,我必须根据休假类型更改列颜色。

But In angular-calendar data it's not working, attendance data is showing null.但是在角度日历数据中它不起作用,出勤数据显示为空。

Here is my code.这是我的代码。

Please help.请帮忙。

import { AfterViewInit, ChangeDetectionStrategy, Component, ViewEncapsulation } from '@angular/core';
import { CalendarDateFormatter, CalendarEvent, CalendarMonthViewBeforeRenderEvent, CalendarView } from 'angular-calendar';
import { Subject } from 'rxjs';
import { AttendanceService } from '../services/attendance.service';

@Component({
  selector: 'amt-staff-attendance-statistics',
  templateUrl: './attendance-statistics.component.html',
  styleUrls: ['./attendance-statistics.component.scss'],
  changeDetection: ChangeDetectionStrategy.OnPush,
  encapsulation: ViewEncapsulation.None
})
export class AttendanceStatisticsComponent implements AfterViewInit{
  view: CalendarView = CalendarView.Month;
  Month: Date = new Date();
  events: CalendarEvent[] = [];
  refresh: Subject<any> = new Subject();
  attendace: any;

  constructor(
    public attendanceService: AttendanceService
  ){}

  getAttendace()
  {
    this.attendanceService.getAttendance().pipe().subscribe(res => {
      this.attendace = res;
    }, error =>{
      console.log("error", error.error.message);
    });
  }

  beforeMonthViewRender(renderEvent: CalendarMonthViewBeforeRenderEvent): void {
    console.log("attendace" ,this.attendace)
    renderEvent.body.forEach((day) => {
      const dayOfMonth = day.date.getDate();
      if(day.isWeekend)
      {
        day.cssClass = "text-red";
      }

    });
  }

  refreshView(): void {
    this.refresh.next();
  }
  

}

HTML HTML


<div [ngSwitch]="view">
  <mwl-calendar-month-view
     *ngSwitchCase="'month'"
     [viewDate]="m"
     [events]="events"
     [refresh]="refresh"
     (beforeViewRender)="beforeMonthViewRender($event)"
   ></mwl-calendar-month-view>
</div>

Thanks.............................................................谢谢................................................. ………………

I have fixed the issue by using refresh function,我已经使用刷新功能解决了这个问题,

refreshView(): void {
   this.refresh.next();
}

and it's called after getting api response,它在获得 api 响应后调用,

this.refresh.next();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM