Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 角度材质日期选择器-下一次单击,上一次单击未发射_Angular_Typescript_Datepicker_Angular Material - Fatal编程技术网

Angular 角度材质日期选择器-下一次单击,上一次单击未发射

Angular 角度材质日期选择器-下一次单击,上一次单击未发射,angular,typescript,datepicker,angular-material,Angular,Typescript,Datepicker,Angular Material,我尝试使用MaterialDatePicker允许用户进行预订。我想在用户单击datepicker中的下个月或上个月时调用内部方法。我可以看到nextClicked和previousClicked的方法,但这些方法似乎没有发出,因此我无法执行自己的操作 <input class="date-selected" [matDatepickerFilter]="checkInFilter" [matDatepicker]="checkInDatepicker" [min]="minDate" (

我尝试使用MaterialDatePicker允许用户进行预订。我想在用户单击datepicker中的下个月或上个月时调用内部方法。我可以看到nextClicked和previousClicked的方法,但这些方法似乎没有发出,因此我无法执行自己的操作

<input class="date-selected" [matDatepickerFilter]="checkInFilter" [matDatepicker]="checkInDatepicker" [min]="minDate" (focus)="checkInDatepicker.open()" [(ngModel)]="checkInDate">
<mat-datepicker #checkInDatepicker (nextClicked)="nextMonth($event)"
    (previousClicked)="previousMonth($event)">
</mat-datepicker>

当用户在datepicker中单击next/previous时,是否还有调用我自己方法的方法?

首先:
nextClicked
previousClicked
都不是事件发射器,因此不会产生任何输出。 检查此项了解更多信息:(两者都是功能)


您可以使用所选的
month
emitter并尝试使其与之配合使用(跟踪更改并相应地调用next/previous),尽管此选项仅在选择月份时有效(即选择年份->选择月份[emitter fires]->选择日期)

日历的标题部分(包含视图切换器和“上一步”和“下一步”按钮的部分)可以根据需要替换为自定义组件。这是使用的calendarHeaderComponent属性完成的。它采用组件类并构造组件的实例用作标头


为了与自定义标题组件中的日历交互,您可以将父MatCalendar注入构造函数。为了确保标题与日历保持同步,请订阅日历的stateChanges observable并标记标题组件以进行更改检测。

我通过实现自定义标头和共享服务

在自定义标头中,我正在调用共享服务中的一个方法,该方法设置了一个变量,并在该变量上有一个可观察的变量

然后在主组件中,我订阅构造函数中的可观察对象,并调用我的自定义方法

自定义头方法

previousClicked(mode: 'month' | 'year') {
    this._calendar.activeDate = mode === 'month' ?
      this._dateAdapter.addCalendarMonths(this._calendar.activeDate, -1) :
      this._dateAdapter.addCalendarYears(this._calendar.activeDate, -1);

    this.calendarService.previousMonthClick(this._dateAdapter.getMonth(this._calendar.activeDate));
}
共享服务

private _previousMonthClick = new Subject();
  previousMonthClick$ = this._previousMonthClick.asObservable();

....

  previousMonthClick(month) {
    this._previousMonthClick.next(month);
  }

主要成分

constructor(private calendarService: CalendarService) {
    calendarService.previousMonthClick$.subscribe(e => this.previousMonth(e));
  }

...
 previousMonth(event) {
    console.log(event);
  }

我已经能够实现自定义标题,但看不到如何在我的主组件中捕获事件。BookingComponent有一个MatDatePicker实例,它正在调用自定义标题组件。当月份发生变化时,我如何在booking组件中知道?
constructor(private calendarService: CalendarService) {
    calendarService.previousMonthClick$.subscribe(e => this.previousMonth(e));
  }

...
 previousMonth(event) {
    console.log(event);
  }