File

projects/angular-calendar/src/modules/common/calendar-today/calendar-today.directive.ts

Description

Change the view date to the current day. For example:

<button
 mwlCalendarToday
 [(viewDate)]="viewDate">
 Today
</button>

Metadata

Index

Inputs
Outputs
HostListeners

Constructor

constructor(dateAdapter: DateAdapter)
Parameters :
Name Type Optional
dateAdapter DateAdapter No

Inputs

viewDate
Type : Date

The current view date

Outputs

viewDateChange
Type : EventEmitter<Date>

Called when the view date is changed

HostListeners

click
import {
  Directive,
  HostListener,
  Input,
  Output,
  EventEmitter,
} from '@angular/core';
import { DateAdapter } from '../../../date-adapters/date-adapter';

/**
 * Change the view date to the current day. For example:
 *
 * ```typescript
 * <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();

  constructor(private dateAdapter: DateAdapter) {}

  /**
   * @hidden
   */
  @HostListener('click')
  onClick(): void {
    this.viewDateChange.emit(this.dateAdapter.startOfDay(new Date()));
  }
}

results matching ""

    No results matching ""