Angular日历:在beforeWeekViewRender事件中添加的自定义css在resize事件中被删除。
创始人
2024-10-29 05:00:32
0

要在Angular日历的beforeWeekViewRender事件中添加自定义CSS,并避免在resize事件中被删除,可以使用以下解决方法:

  1. 在组件的构造函数中引入Renderer2模块,并注入到构造函数中:
import { Component, OnInit, Renderer2 } from '@angular/core';

constructor(private renderer: Renderer2) { }
  1. 在ngAfterViewInit生命周期钩子中添加事件监听器,并在事件处理程序中设置自定义CSS:
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);
  });
}
  1. 在resize事件中重新添加自定义CSS:
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样式,避免被删除。请根据实际需求进行调整,并将代码添加到你的组件中。

相关内容

热门资讯

2分钟辅助!wepoker手机... 2分钟辅助!wepoker手机助手,pokermaster辅助器,法子教程(有挂工具)亲,关键说明,...
第五分钟辅助!pokemmo辅... 第五分钟辅助!pokemmo辅助器手机版下载,拱趴大菠萝怎么开挂,教材教程(有挂功能)1、玩家可以在...
五分钟辅助!hhpoker是真... 五分钟辅助!hhpoker是真的还是假的,哈糖大菠萝有挂吗,积累教程(有挂详情)1、每一步都需要思考...
八分钟辅助!epoker免费透... 八分钟辅助!epoker免费透视脚本,hhpoker辅助器,手段教程(有挂透明挂)1、每一步都需要思...
第二分钟辅助!we-poker... 第二分钟辅助!we-poker正规吗,hhpoker一直输有挂吗,总结教程(的确有挂)1、hhpok...
八分钟辅助!pokermast... 八分钟辅助!pokermaster辅助器,wpk透视插件,策略教程(有挂方法)1、pokermast...
2分钟辅助!拱趴大菠萝有什么挂... 2分钟辅助!拱趴大菠萝有什么挂,hhpoker必备开挂,烘培教程(有挂秘籍)1、拱趴大菠萝有什么挂公...
4分钟辅助!wepoker软件... 4分钟辅助!wepoker软件靠谱么,wepoker免费脚本,法门教程(有挂详细)1、用户打开应用后...
第九分钟辅助!wepoker有... 第九分钟辅助!wepoker有脚本吗,wepoker透视脚本免费app,手筋教程(有挂方式)1、we...
第九分钟辅助!德普之星私人局辅... 第九分钟辅助!德普之星私人局辅助器,德普之星辅助工具如何打开,步骤教程(有挂猫腻)1、德普之星辅助工...