简体   繁体   English

(Angular) 如何禁用组件模板中的“链接”标签?

[英](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.

相关问题 如何禁用 Angular 中不同组件中的按钮? - How can I disable a button thats in a different component in Angular? 如何动态设置angular2组件标签的样式? - How can i style an angular2 component tag dynamically? 如何在 Angular 组件中呈现带有上下文的模板? - How can I render template with context in an Angular component? 如何将预先生成的数组按角度传递给模板中的组件? - How can I pass pre generated array to component in template in angular? 如何在 angular 组件的模板中访问服务的变量 - how can I access the variables of a service in the template of a component in angular 在Angular中,如何从组件模板周围删除选择器标签? - In Angular, how to remove the selector tag from around the component's template? Angular:如何访问父组件中的子组件模板变量? - Angular: How can I access Child Component template variable in parent Component? 我为什么不能使用 <template> 作为angular2组件模板? - Why can't I use <template> as an angular2 component template? 如何在Angular2中为模板的一部分禁用模板绑定? - How do I disable template binding in for part of template in Angular2? 用其模板完全替换Angular组件标签 - Completely replace Angular component tag with its template
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM