【问题标题】:angular change css files and make effect角度更改css文件并生效
【发布时间】:2019-03-18 23:53:56
【问题描述】:

现在我有 2 个 css 文件 (ltr.css/rtl.css) 我已在 angular.json 文件中默认导入文件或从 index.html 导入它,它们工作得很好, 但是当在 index.html 中默认加载一个并尝试通过 js 在角度服务中将一个更改为另一个时,href 发生了变化,但样式不像我默认加载它那样需要重新加载页面或刷新

html css 标签

这是我将 css 更改为另一个的代码

initLayoutAlign(){
    this.translate.get('LANGALIGN').subscribe((align)=>{
        this.document.getElementById('style-bandle').setAttribute('href','assets/demo/default/base/style.bundle'+(align=='rtl'?'.rtl':'')+'.css');
    })
}

【问题讨论】:

    标签: javascript html css angularjs angular


    【解决方案1】:

    好像有条件问题--

    改一下

    this.document.getElementById('style-bandle').setAttribute('href','assets/demo/default/base/style.bundle'+(align=='rtl'?'.rtl':'')+'.css');
    

    this.document.getElementById('style-bandle').setAttribute('href','assets/demo/default/base/style.bundle'+align+'.css');
    

    这将指向style.bundle.rtl.cssstyle.bundle.ltr.css

    【讨论】:

    • 谢谢,但条件很好,但我发现我从 angular.json 中删除了 css 文件,但之后我没有重新提供 angular 来查看更改,所以它现在工作得很好但是有一秒钟,css文件正在改变网页现在只有css文本
    猜你喜欢
    • 1970-01-01
    • 2018-08-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-29
    • 2012-11-13
    相关资源
    最近更新 更多