我的登录页面和应用程序中的其他页面具有不同的类,因此在用户登录后,我需要更改body元素的类。在这里,我试图做到这一点。
index.html
<body [ngClass]="{
'dashboard site-navbar-small' :isAuthenticated,
'login-form login-form-second page-login-second' :!isAuthenticated
}">
<app-root>Loading...</app-root>
Run Code Online (Sandbox Code Playgroud)
login.component.ts
export class LoginComponent {
@HostBinding('class.login-form.login-form-second.page-login-second')
siteNavbarSmallClass = false;
constructor(private auth:Auth){
this.siteNavbarSmallClass=this.auth.authenticated();
}
}
Run Code Online (Sandbox Code Playgroud)
app.component.ts
export class AppComponent {
@HostBinding('class.dashboard.site-navbar-small')
dashboardClass = false;
constructor(private auth:Auth){
this.dashboardClass=this.auth.authenticated();
}
}
Run Code Online (Sandbox Code Playgroud)
我正在尝试将ngClass指令绑定到isAuthenticated字段..但我不受影响。我听说我们无法通过ts更改body元素,但是我该如何处理呢?