Bumveloper
Bumveloper

Reputation: 85

(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,

  <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.

So how can I disable the css?

Upvotes: 1

Views: 229

Answers (2)

Bumveloper
Bumveloper

Reputation: 85

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:

ngOnDestroy(){
this.disableCSS("board.css", false);
}

Upvotes: 1

SK.
SK.

Reputation: 1510

$('link[href="assets/css/1.css"]').each(function() { this.remove(); });

You need to put this inside jquery onload fucntion

Upvotes: 1

Related Questions