MatDatepickerFilter - 过滤器函数无法访问类变量 [英] MatDatepickerFilter - Filter function can't access class variable

查看:23
本文介绍了MatDatepickerFilter - 过滤器函数无法访问类变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一个带有过滤器的 MatDatePicker 定义如下:

A MatDatePicker with a filter defined as followed:

<mat-form-field class="example-full-width">
  <input matInput [matDatepickerFilter]="myFilter" [matDatepicker]="picker" placeholder="Choose a date">
  <mat-datepicker-toggle matSuffix [for]="picker"></mat-datepicker-toggle>
  <mat-datepicker #picker></mat-datepicker>
</mat-form-field>

export class DatepickerFilterExample {
  someDateToBlock: number = 3;
  myFilter = (d: Date): boolean => {
    const day = d.getDay();
    // THIS FUNCTION CANNOT ACCESS THE VARIABLE 'someDateToBlock'
    return day !== 0 && day !== 6;
  }
}

我想访问过滤器函数中的变量 someDateToBlock(或任何其他).是否有解决方法可以使这种情况成为可能?

I would like to access the variable someDateToBlock (or any other) in the filter function. Is there a workaround to make this possbile?

推荐答案

这是有效的,这里是 plunkr 链接:https://plnkr.co/edit/oRGfxLSrn6GdfRhYO1rr?p=preview

This is working, here is plunkr link: https://plnkr.co/edit/oRGfxLSrn6GdfRhYO1rr?p=preview

export class DatepickerOverviewExample {
  someDateToBlock: number = 3;
  myFilter = (d: Date): boolean => {
    const day = d.getDay();
    // THIS FUNCTION CANNOT ACCESS THE VARIABLE 'someDateToBlock'
    return this.someDateToBlock;
  }
}

我也检查了 alert(this.someDateToBlock)

I checked with alert(this.someDateToBlock) also

这篇关于MatDatepickerFilter - 过滤器函数无法访问类变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆