close

[Solved] Cannot read property ‘remove’ of undefined at BrowserDomAdapter.removeClass

Hello Guys, How are you all? Hope You all Are Fine. Today I am Facing the following error Cannot read property ‘remove’ of undefined at BrowserDomAdapter.removeClass in angular. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How Cannot read property ‘remove’ of undefined at BrowserDomAdapter.removeClass Error Occurs ?

I am Facing the following error.

Cannot read property 'remove' of undefined at BrowserDomAdapter.removeClass

Here is my code.

  <li *ngClass="{active: data==='data1'}" (click)="data='data1'">Data1</li>

How To Solve Cannot read property ‘remove’ of undefined at BrowserDomAdapter.removeClass Error ?

  1. How To Solve Cannot read property 'remove' of undefined at BrowserDomAdapter.removeClass Error?

    To Solve Cannot read property 'remove' of undefined at BrowserDomAdapter.removeClass Error is only for the shorthand syntax for structural directives where you can for example use {{data}}

  2. Cannot read property 'remove' of undefined at BrowserDomAdapter.removeClass

    To Solve Cannot read property 'remove' of undefined at BrowserDomAdapter.removeClass Error is only for the shorthand syntax for structural directives where you can for example use {{data}}

Solution 1

Use one of the below classes conditionally.

condition 1

[class.my_class] = "data=== 'data1'"

condition 2

[ngClass]="{'my_class': data=== 'data1'}"

condition 3

[ngClass]="{'my_class': data === 'data1', 'my_class2' : data === 'data2' }"

condition 4

[ngClass]="{1 : 'my_class1', 2 : 'my_class2', 3 : 'my_class4'}[data]"

condition 5

[ngClass]="data == 'data1' ? 'my_class1' : 'my_class2'"

Solution 2

Consider to use [class.active]

Example :

<ol class="breadcrumb">
    <li [class.active]="data=='data1'" (click)="data='data1'">data1</li>
</ol>

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you?

Also Read

Please Rate Our Solution to Motivate Us For Give Our Best

Leave a Comment