how to change class of body in angular2&typescript project

前端 未结 3 343
温柔的废话
温柔的废话 2021-01-19 22:55

I have diffirent classes for login page and other pages in application so after user logged in I need to change class of body element. Here how I am trying to accomplish thi

3条回答
  •  旧巷少年郎
    2021-01-19 23:36

    Bindings outside are not supported.

    What you can do is to use selector: 'body' in you AppComponent and

    @HostBinding('class.dashboard')
    dashboardClass = false;
    
    @HostBinding('class.site-navbar-small')
    siteNavbarSmallClass = false;
    
    ...
    

    and then set the properties to true to get the classes added.

    or just

    document.body.classList.add('dashboard');
    

提交回复
热议问题