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:
[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'"
Related Posts:
- Angular: conditional class with *ngClass
- Angular: conditional class with *ngClass
- Crop the image using JavaScript
- Failed to load resource: the server responded with a status of 404 (Not Found)
- Failed to load resource: the server responded with a status of 404 (Not Found)
- How to change CSS using jQuery?
- Can’t bind to ‘ngModel’ since it isn’t a known property of ‘input’
- Remove class using jQuery
- How can I scroll to an element using jQuery?
- What is an unhandled promise rejection?
- “Uncaught TypeError: Cannot read property ‘style’ of null at.. “
- What is the meaning of == $0 that is shown in inspect element of google chrome for the selected element [duplicate]
- Angular: mat-form-field must contain a MatFormFieldControl
- (change) vs (ngModelChange) in angular
- Bootstrap Dropdown menu is not working
- Change Background color (css property) using Jquery
- Cannot find module ‘@angular-devkit/core’
- No value accessor for form control
- Using Javascript in CSS
- Set timeout for ajax (jQuery)
- Angular: Error no directive with “exportAs” set to “ngForm”
- Angular ForEach in Angular4/Typescript?
- How to generate a simple popup using jQuery
- How does the data-toggle attribute work? (What’s its API?)
- CSS height 100% percent not working
- Angular 4 setting selected option in Dropdown
- Use images like checkboxes
- Adding images to a Bootstrap Carousel with AJAX
- Completely disable scrolling of webpage
- Angular4 – No value accessor for form control
- Setting background-image using jQuery CSS property
- How do you Hover in ReactJS? – onMouseLeave not registered during fast hover over
- Uncaught TypeError: Cannot read property ‘top’ of undefined
- npm WARN … requires a peer of … but none is installed. You must install peer dependencies yourself
- Full-screen iframe with a height of 100%
- How to add multiple classes to a ReactJS Component?
- Change CSS of class in Javascript?
- What is ViewChild in Angular2?
- How to print HTML content on click of a button, but not the page?
- Equivalent of jQuery .hide() to set visibility: hidden
- Bootstrap 4 Dropdown Menu not working?
- Module not found: Error: Can’t resolve ‘fs’ in
- TypeError: $(…).modal is not a function with bootstrap Modal
- Why is the jquery script not working?
- How to do fade-in and fade-out with JavaScript and CSS
- TypeError: $(…).DataTable is not a function
- Change text on hover, then return to the previous text
- CSS Animation onClick
- Textarea Auto height
- Angular 2 – Using ‘this’ inside setTimeout
- How to fix Cannot find module ‘typescript’ in Angular 4?
- Mixed Content Page: requested an insecure stylesheet error
- Why is marquee deprecated and what is the best alternative?
- Refresh/reload the content in Div using jquery/ajax
- How to write inside a DIV box with javascript
- How to get height of div in px dimension
- How to set Angular 4 background image?
- SyntaxError: Unexpected token C in JSON at position 0 – Ionic 2 Http GET request
- Force div to be topmost element of any and all webpages
- Retrieve the position (X,Y) of an HTML element
- How to display raw JSON data on a HTML page
- Angular 4 setTimeout() with variable delay and wait
- What does the .subscribe() function do?
- “Uncaught TypeError: a.indexOf is not a function” error when opening new foundation project
- how to display a div triggered by onclick event
- Why is jquery show() not working in example
- jQuery scrollTop() method not working
- Angular 2 Hover event
- Set CSS property in JavaScript?
- Change an image with onclick()
- JavaScript – Count Number of Visitor for Website
- Creating Accordion Table with Bootstrap
- Getting or changing CSS class property with Javascript using DOM style
- How do I download a file with Angular2 or greater
- What are differences between SystemJS and Webpack?
- Fully responsive HTML5 video
- How to create checkbox inside dropdown?
- How to use forEach loop correctly in angular 2?
- How to change cursor from pointer to finger using jQuery?
- Angular 2 Sort table columns
- Positioning element at center of screen
- How to use onBlur event on Angular2?
- Adding Google Translate to a web site
- Bootstrap Collapse not Collapsing
- How do I install Angular 2 using NPM?
- Cannot read property ‘style’ of undefined — Uncaught Type Error
- How can I remove a style added with .css() function?
- How to make HTML element resizable using pure Javascript?
- How to use aria-expanded=”true” to change a css property
- How to set “style=display:none;” using jQuery’s attr method?
- Using Angular 2 without TypeScript Transpiler
- WordPress Bootstrap Handburger Menu Wont Open
- Correct way to include extra styles & script files?
- WP adds long version query strings to CSS and JS files
- WordPress getting css and script files from client machine rather than the server machine
- Hide CSS class only in single post pages
- How to keep close a sub-menu under homepage? [closed]
- How to get the browser viewport dimensions?
- Javascript, viewing [object HTMLInputElement]
- How to insert html/css/javascript code to wordpress plugin