简体   繁体   English

身体上的angular4 ng级,在不同路线上

[英]angular4 ng-class on body, on different routes

I am applying condition based class on body tag , when we on login, then abc class will be apply on login, otherwise simple default body tag will be apply. 我将基于条件的类应用于body标签,当我们登录时,则abc类将应用于登录,否则将应用简单的默认body标签。

<body *ngIf="router.url === '/login': 'class.my-class'">

But its not working. 但是它不起作用。 Can anyone tell me how can i do this with angular 2 or 4. 谁能告诉我如何用角度2或角度4做到这一点。

This example expects that you already get the url in your component via router.url . 此示例期望您已经通过router.url获得了组件中的url

ngIf will not add class to the element. ngIf不会将class添加到元素。 Instead you can use 相反,您可以使用

<body [class.my-class]="router.url === '/login'" >

For more you can read Documentation 有关更多信息,请阅读文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM