1

I am adding a class to 2 div to toggle sidebar header using [ngClass] how do i remove those class when enlarge the screen.

enter image description here

The problem is on widening the screen it remains there only because class is not removed. How do i remove the class?

On adding class [ngClass]="{'menu-push-onscreen': show}" it will toggle and when i widen screen it will be there itself how shall i remove that?

show: boolean = false;

 onToggleHeader(){
   this.show=!this.show;

}

Mistalis
  • 17,793
  • 13
  • 73
  • 97
Samson Maben
  • 310
  • 2
  • 4
  • 15

2 Answers2

1

Just set the [ngClass] binding to null. Here is an example:

In your component.html:

<div [ngClass]="myClass"></div>

In your component class:

...
// Declare varibale
myClass:string;

// Set some variable to true if the screen widening
if(isScreenWidening){
    this.myClass = null;
}
...
FAISAL
  • 33,618
  • 10
  • 97
  • 105
0
@media screen and (max-width: 600px) { // this is for screen width less than equal to 600px

  .yourClass{
     // remove all the properties you might have set
  }
}

If you need to add more media queries as per screen size change the max or min width.

Rahul Singh
  • 19,030
  • 11
  • 64
  • 86