这个问题已经在这里有一个答案:
下面的问题是在角7
<header class="stick-top forsticky gradient">
这里是我的角度HTML内容
current_path = localStorage.getItem("current_path");
当前路径是在我的组件的变量。
我想,如果做的current_path!=在组件“/”,那么赫德会是这样。
<header class="stick-top forsticky gradient">
其他
<header class="stick-top forsticky">
我想从标题标签去除梯度类,如果我是的current_path“/”
您可以使用ngClass:
<header class="stick-top forsticky" [ngClass]="{'gradient':current_path != '/'}">
如果它是一个单独的类,足够好的替代ngClass是
<header class="stick-top forsticky" [class.gradient]=" current_path != '/' " >
因为它更容易格式和比解析类JS对象的HTML模板美化你可能更喜欢这种语法。