How do I change the body class via a typescript class (angular2)

前端 未结 7 1842
失恋的感觉
失恋的感觉 2020-12-14 02:04

How do I change the body class via the root component?

@Component({ 
   selector: \"app\", 
   directives: [ROUTER_         


        
相关标签:
7条回答
  • 2020-12-14 03:09

    Here you can simple use the native JavaScript in the Angular2 component to change the class of the <body> tag:-

    let body = document.getElementsByTagName('body')[0];
    body.classList.remove("className");   //remove the class
    body.classList.add("className");   //add the class
    
    0 讨论(0)
提交回复
热议问题