Angular conditional class with ngClass

0 votes

What seems to be wrong with my Angular code because I am getting the following error repeatedly :

Cannot read property 'remove' of undefined at BrowserDomAdapter.removeClass
<ol> 
    <li *ngClass="{active: step==='step1'}" (click)="step='step1'">Step1</li>
    <li *ngClass="{active: step==='step2'}" (click)="step='step2'">Step2</li> 
    <li *ngClass="{active: step==='step3'}" (click)="step='step3'">Step3</li> 
</ol>
Feb 9 in Java by Soham
• 8,730 points
49 views

1 answer to this question.

0 votes

For your information, the latest Angular version 2+ provides several ways and types:-

type one
[class.my_class] = "step === 'step1'"
type two
[ngClass]="{'my_class': step === 'step1'}"

and multiple option:

[ngClass]="{'my_class': step === 'step1', 'my_class2' : step === 'step2' }"
type three
[ngClass]="{1 : 'my_class1', 2 : 'my_class2', 3 : 'my_class4'}[step]"

type four
[ngClass]="step == 'step1' ? 'my_class1' : 'my_class2'"

answered Feb 9 by Rahul
• 8,980 points

Related Questions In Java

+5 votes
4 answers

How to execute a python file with few arguments in java?

You can use Java Runtime.exec() to run python script, ...READ MORE

answered Mar 27, 2018 in Java by DragonLord999
• 8,450 points

edited Nov 7, 2018 by Omkar 59,144 views
0 votes
2 answers

“Could not find or load main class” mean?

Use the final modifier to enforce good initialization. Avoid returning ...READ MORE

answered Sep 18, 2018 in Java by Sushmita
• 6,900 points
3,082 views
0 votes
3 answers

How to read input from Console using Scanner Class?

A simple example: import java.util.Scanner; public class Expl { ...READ MORE

answered Aug 1, 2018 in Java by samarth295
• 2,220 points
2,810 views
0 votes
1 answer

What are the vulnerability related to PHP Form?

Hii, The $_SERVER["PHP_SELF"] variable can be used by ...READ MORE

answered Feb 13, 2020 in PHP by Niroj
• 82,680 points
1,040 views
+1 vote
1 answer

How can we send message multiple time to a specific person or group in whatsapp using loop?

Hii @kartik,  This is simple task to send single ...READ MORE

answered Feb 28, 2020 in Java-Script by Niroj
• 82,680 points
5,079 views
0 votes
1 answer

Why it is necessary to refresh CSRF token per form request?

Hello, Generating a new CSRF token for each ...READ MORE

answered Mar 19, 2020 in Laravel by Niroj
• 82,680 points
2,660 views
0 votes
1 answer

What is meant by passing the variable by value and reference in PHP?

Hello, When the variable is passed as value ...READ MORE

answered Mar 27, 2020 in PHP by Niroj
• 82,680 points
1,252 views
0 votes
1 answer

Problem with gif with transparent background

In this case, I have noticed that ...READ MORE

answered Feb 8 in Java by Rahul
• 8,980 points
36 views
0 votes
1 answer

Failed to load resource: the server responded with a status of 404 (not found)

In order to avoid an error while ...READ MORE

answered Feb 8 in Java by Rahul
• 8,980 points
45 views
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP