Javascript 使用Mat datepicker以多种颜色高亮显示日期
我有两套日期,需要使用角度矩阵日期选择器以橙色和红色突出显示 例如,用户输入将如下所示Javascript 使用Mat datepicker以多种颜色高亮显示日期,javascript,angular,typescript,datepicker,angular-material,Javascript,Angular,Typescript,Datepicker,Angular Material,我有两套日期,需要使用角度矩阵日期选择器以橙色和红色突出显示 例如,用户输入将如下所示 const dateInOrange = [1,5,10,20] const dateInRed = [10,22,27] 到目前为止,我可以突出显示日期的橙色,但红色没有突出显示 请帮助下面是我的stackblitz链接 你的橘子全熟了,所以每次回来我都会多拿一个 private _setupClassFunction() { this.dateClass = (d: Date) => {
const dateInOrange = [1,5,10,20]
const dateInRed = [10,22,27]
到目前为止,我可以突出显示日期的橙色,但红色没有突出显示
请帮助下面是我的stackblitz链接
你的橘子全熟了,所以每次回来我都会多拿一个
private _setupClassFunction() {
this.dateClass = (d: Date) => {
let selected = false;
if (this._orangeDatesArray) {
selected = this._orangeDatesArray.some(
(item: Date) =>
item.getFullYear() === d.getFullYear() &&
item.getDate() === d.getDate() &&
item.getMonth() === d.getMonth()
);
if(selected){
return selected ? "example-custom-date--orange-class " : undefined;
}
else if (this._redDatesArray) {
selected = this._redDatesArray.some(
(item: Date) =>
item.getFullYear() === d.getFullYear() &&
item.getDate() === d.getDate() &&
item.getMonth() === d.getMonth()
);
return selected ? "example-custom-date--red-class " : undefined;
}
}
};
}您可以在两个位置使用this one功能
private _setupClassFunction() {
this.dateClass = (d: Date) => {
let selected = false;
var className = "";
selected = this._redDatesArray.some(
(item: Date) =>
item.getFullYear() === d.getFullYear() &&
item.getDate() === d.getDate() &&
item.getMonth() === d.getMonth()
);
className = selected ? "example-custom-date--red-class " : "";
selected = this._orangeDatesArray.some(
(item: Date) =>
item.getFullYear() === d.getFullYear() &&
item.getDate() === d.getDate() &&
item.getMonth() === d.getMonth()
);
className+= selected ? "example-custom-date--orange-class " : "";
return className;
};
Cagri的解决方案也是一个很好的解决方案。您只有orange类的返回语句,请检查第68行