0

Below question is in angular 7

<header class="stick-top forsticky gradient">

Here is my html content in angular

current_path = localStorage.getItem("current_path");

current path is a variable in my component.

I wants to make if current_path != '/' in component then heder will be like this.

<header class="stick-top forsticky gradient">

else

<header class="stick-top forsticky">

I wants to remove gradient class from hrader tag if my current_path is '/'

2 Answers2

4

you can use ngClass:

<header class="stick-top forsticky" [ngClass]="{'gradient':current_path != '/'}">
Fateme Fazli
  • 11,582
  • 2
  • 31
  • 48
2

If it is a single class, a good enough alternative to ngClass is

<header class="stick-top forsticky" [class.gradient]=" current_path != '/' " >

You may prefer this syntax since it is easier to format and prettify in the html templates than js objects that resolve to classes.

Dhananjai Pai
  • 5,914
  • 1
  • 10
  • 25