Quantcast
Channel: Angular: conditional class with *ngClass - Stack Overflow
Browsing index pages (27 articles)

Answer by chaika for Angular: conditional class with *ngClass

Use [ngClass] instead of *ngClass.<ol><li [ngClass]="{'active': step === 'step1'}" (click)="step='step1'">Step1</li></ol>

View Article


Answer by OMANSAK for Angular: conditional class with *ngClass

Some usefull helper pipes for ngClass@Pipe({ name: 'condition'})export class ONgConditionPipe implements PipeTransform { transform(value: any, condition?: any): any { if (condition != null) { return...

View Article


Angular: conditional class with *ngClass

What is wrong with my Angular code? I am getting the following error:Cannot read property 'remove' of undefined at BrowserDomAdapter.removeClass<ol><li *ngClass="{active: step==='step1'}"...

View Article

Answer by Günter Zöchbauer for Angular: conditional class with *ngClass

[ngClass]=... instead of *ngClass.* is only for the shorthand syntax for structural directives where you can for example use<div *ngFor="let item of items">{{item}}</div>instead of the...

View Article

Answer by Thierry Templier for Angular: conditional class with *ngClass

You should use something ([ngClass] instead of *ngClass) like that:<ol class="breadcrumb"><li [ngClass]="{active: step==='step1'}" (click)="step='step1; '">Step1</li> (...)

View Article


Answer by Joel Almeida for Angular: conditional class with *ngClass

Another solution would be using [class.active].Example :<ol class="breadcrumb"><li [class.active]="step=='step1'" (click)="step='step1'">Step1</li></ol>

View Article

Answer by MostafaMashayekhi for Angular: conditional class with *ngClass

Angular version 2+ provides several ways to add classes conditionally:type one [class.my_class] = "step === 'step1'"type two [ngClass]="{'my_class': step === 'step1'}"and multiple option:...

View Article

Answer by Alireza for Angular: conditional class with *ngClass

That's the normal structure for ngClass is:[ngClass]="{'classname' : condition}"So in your case, just use it like this...<ol class="breadcrumb"><li [ngClass]="{'active': step==='step1'}"...

View Article


Answer by Jameel Moideen for Angular: conditional class with *ngClass

You can use ngClass to apply the class name both conditionally and not in AngularFor Example [ngClass]="'someClass'">Conditional[ngClass]="{'someClass': property1.isValid}">Multiple Condition...

View Article


Answer by Sarvar Nishonboyev for Angular: conditional class with *ngClass

While I was creating a reactive form, I had to assign 2 types of class on the button. This is how I did it:<button type="submit" class="btn"...

View Article

Answer by Ninad Kulkarni for Angular: conditional class with *ngClass

This is what worked for me:[ngClass]="{'active': dashboardComponent.selected_menu == 'profile'}"

View Article

Answer by Robert Leeuwerink for Angular: conditional class with *ngClass

to extend MostafaMashayekhi his answer for option two>you can also chain multiple options with a ','[ngClass]="{'my-class': step=='step1', 'my-class2':step=='step2' }"Also *ngIf can be used in some...

View Article

Answer by Chaitanya Nekkalapudi for Angular: conditional class with *ngClass

with the following examples you can use 'IF ELSE'<p class="{{condition ? 'checkedClass' : 'uncheckedClass'}}"><p [ngClass]="condition ? 'checkedClass' : 'uncheckedClass'"><p...

View Article


Answer by Rohit.007 for Angular: conditional class with *ngClass

In Angular 7.XThe CSS classes are updated as follows, depending on the type of the expression evaluation:string - the CSS classes listed in the string (space delimited) are addedArray - the CSS classes...

View Article

Answer by Abdus Salam Azad for Angular: conditional class with *ngClass

Let, YourCondition is your condition or a boolean property, then do like this[class.yourClass]="YourCondition"

View Article


Answer by Chirag for Angular: conditional class with *ngClass

ngClass syntax:[ngClass]="{'classname' : conditionFlag}"You can use like this: <ol class="breadcrumb"><li [ngClass]="{'active': step==='step1'}"...

View Article

Answer by Hamza Khanzada for Angular: conditional class with *ngClass

Not relevant with [ngClass] directive but I was also getting the same error asCannot read property 'remove' of undefined at...and I thought to be the error in my [ngClass] condition but it turned out...

View Article


Answer by Alper BULUT for Angular: conditional class with *ngClass

Additionally, you can add with method function:In HTML<div [ngClass]="setClasses()">...</div>In component.ts// Set Dynamic Classes setClasses() { let classes = { constantClass:...

View Article

Answer by amarbhanu for Angular: conditional class with *ngClass

<div class="collapse in " [ngClass]="(active_tab=='assignservice' || active_tab=='manage')?'show':''" id="collapseExampleOrganization" aria-expanded="true" style=""><ul> <li...

View Article

Answer by Waleed Shahzaib for Angular: conditional class with *ngClass

You can use [ngClass] or [class.classname], both will work the same.[class.my-class]="step==='step1'"   OR[ngClass]="{'my-class': step=='step1'}"Both will work the same!

View Article
Browsing index pages (27 articles)


Latest Images