如果用户登录或者不登录,我需要改变class的值,我在app.component.ts和login.component.ts这里检查了它们;用ngClass设置body元素的class属性值
app.component.ts
export class AppComponent {
isAuthenticated:boolean;
constructor(private auth:Auth){
this.isAuthenticated=this.auth.authenticated();
}
}
login.component.ts
export class LoginComponent {
isAuthenticated:boolean;
constructor(private auth:Auth){
this.isAuthenticated=this.auth.authenticated();
}
}
和index.html
<body [ngClass]="{
'dashboard site-navbar-small' :isAuthenticated,
'login-form login-form-second page-login-second' :!isAuthenticated
}">
<app-root>Loading...</app-root>
你能告诉我它不起作用吗? –
我觉得最后一次编辑更清楚了,什么都行不通。我期望一个类的值设置为属性,但你看到它的原始字符串typecrpt代码 – TyForHelpDude
你如何解决它? –