[英](Angular) How can I disable 'link' tag in component template?
為了用一個例子解釋當前的情況,我在“index.html”中使用“link”標簽導入了“1.css”以供全局使用,
<link href="assets/css/1.css" rel="stylesheet" type="text/css" />
在a,b,c三個組件中,我不會使用"c"組件模板中的"1.css"。
那么如何禁用css呢?
$('link[href="assets/css/1.css"]').each(function() { this.remove(); });
你需要把它放在jquery onload fucntion里面
我是這樣解決這個問題的。
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;
}
}
}
}
}
並像 thie 一樣重新禁用 CSS:
ngOnDestroy(){
this.disableCSS("board.css", false);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.