要在Angular日历的beforeWeekViewRender事件中添加自定义CSS,并避免在resize事件中被删除,可以使用以下解决方法:
import { Component, OnInit, Renderer2 } from '@angular/core';
constructor(private renderer: Renderer2) { }
ngAfterViewInit() {
this.renderer.listen('window', 'beforeunload', () => {
// 添加自定义CSS
const customCss = document.createElement('style');
customCss.type = 'text/css';
customCss.innerHTML = '.custom-class { background-color: yellow; }';
document.head.appendChild(customCss);
});
}
ngAfterViewInit() {
this.renderer.listen('window', 'resize', () => {
// 重新添加自定义CSS
const customCss = document.createElement('style');
customCss.type = 'text/css';
customCss.innerHTML = '.custom-class { background-color: yellow; }';
document.head.appendChild(customCss);
});
}
通过这种方式,你可以确保在resize事件中重新添加自定义CSS样式,避免被删除。请根据实际需求进行调整,并将代码添加到你的组件中。
下一篇:Angular日期的奇怪行为