[英](Angular) How can I disable 'link' tag in component template?
To explain the current situation with an example, I imported "1.css" using "link" tag in "index.html" for global use,为了用一个例子解释当前的情况,我在“index.html”中使用“link”标签导入了“1.css”以供全局使用,
<link href="assets/css/1.css" rel="stylesheet" type="text/css" />
Among the three components a,b,c, I wont to use the "1.css" in the template of the "c" component.在a,b,c三个组件中,我不会使用"c"组件模板中的"1.css"。
So how can I disable the css?那么如何禁用css呢?
$('link[href="assets/css/1.css"]').each(function() { this.remove(); }); $('link[href="assets/css/1.css"]').each(function() { this.remove(); });
You need to put this inside jquery onload fucntion你需要把它放在jquery onload fucntion里面
I solve this problem like this.我是这样解决这个问题的。
ngOnInit(): void{
this.disableCSS("1.css", true);
}
...
disableCSS(cssFileName: string){
for (let i = 0; i<= document.styleSheets.length; i++ ){
if( typeof document.styleSheets[i] !== 'undefined' ){
if( typeof document.styleSheets[i].href !== "undefined" && document.styleSheets[i].href !== null){
if( document.styleSheets[i].href.includes( cssFileName ) ){
document.styleSheets[i].disabled = true;
}
}
}
}
}
and re disable CSS like thie:并像 thie 一样重新禁用 CSS:
ngOnDestroy(){
this.disableCSS("board.css", false);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.