src/directives/calendarToday.directive.ts
Change the view date to the current day. For example:
<button
mwlCalendarToday
[(viewDate)]="viewDate">
Today
</button>
selector | [mwlCalendarToday] |
viewDate
|
The current view date
Type: |
viewDateChange
|
Called when the view date is changed $event type: any
|
import { Directive, HostListener, Input, Output, EventEmitter } from '@angular/core';
import startOfToday from 'date-fns/start_of_today';
/**
* Change the view date to the current day. For example:
*
* ```
* <button
* mwlCalendarToday
* [(viewDate)]="viewDate">
* Today
* </button>
* ```
*/
@Directive({
selector: '[mwlCalendarToday]'
})
export class CalendarTodayDirective {
/**
* The current view date
*/
@Input() viewDate: Date;
/**
* Called when the view date is changed
*/
@Output() viewDateChange: EventEmitter<Date> = new EventEmitter();
/**
* @hidden
*/
@HostListener('click')
onClick(): void {
this.viewDateChange.emit(startOfToday());
}
}