angular - 如何更改 Mat-Calandar 中的显示值
问题描述
我正在为我的项目准备一份出勤日历。我可以用他/她的出勤状态显示垫子日历和大灯日期。
timeIn
现在,我想timeOut
在mat-calendar
.
我的服务器数据看起来像
attendance = [
{ attDate: '2020-04-01', timeIn: '09:00', timeOut: '21:00', status: null },
{ attDate: '2020-04-21', timeIn: '09:00', timeOut: '21:00', status: 'A' },
];
要显示的日期
1
09:00 - 21:00
21
09:00 - 21:00
如何更改显示值mat-calendar
?
创建了一个stackblitz以供快速参考。
我正在使用Angular9
和Angular Material
解决方案
我发现的唯一解决方法是使用::after伪元素添加时间。我使用attr() css 函数来设置时间内容,但您也可以使用 css 变量和var()函数。
// app.component.ts
...
export class AppComponent implements AfterViewInit {
...
constructor(
private readonly elementRef: ElementRef) {
}
ngAfterViewInit() {
const htmlElement: HTMLElement = this.elementRef.nativeElement;
for (let [cellClass, date] of [
['holi-date', this.attendance[0]],
['green-date', this.attendance[1]]
] as const) {
const dateElement = htmlElement.getElementsByClassName(cellClass).item(0);
dateElement.setAttribute('data-date-time', `${date.timeIn} - ${date.timeOut}`);
}
}
// styles.scss
...
[data-date-time]::after {
content: attr(data-date-time);
position: absolute;
display: block;
left: 0;
right: 0;
bottom: 1em;
}
推荐阅读
- php - Symfony - findOneOrFail 返回数组消息
- python - 用于 CPU 调度的循环调度算法的 Python 代码
- python - 如何在不传递pyspark json中的父属性的情况下访问嵌套属性
- asp.net - 我们如何从后面的代码中显示确认消息框并基于确认,在 ASP.net VB 中执行进一步的操作?
- pycharm - 配置python解释器PyCharm 2020.1 WSL2
- python - 如何使数据进入同一行
- java - 自定义 QueryDsl 绑定以在地图字段上进行搜索
- visual-studio-code - VSCode更改终端中取消信号的键绑定
- azure - 无法在 Azure 中删除所有权保护以将域转移到 Godaddy
- javascript - Vue Js Element UI如何在表格列中呈现数组对象