The ngClass directive allows you to dynamically set CSS classes on an HTML element by databinding an expression that represents all classes to be added.
Questions tagged [angularjs-ng-class]
63 questions
6
votes
2 answers
How to add and remove class with AngularJS?
I have a few buttons that work like switchers. If you click one it becomes active and "shuts down" other buttons. I did this using jQuery but would like to use AngularJS. Here is my code:
HTML
6
votes
3 answers
Add a class selectively to an ng-repeat AngularJS
I have an ng-repeat for a table, I want to be able to add a class when is clicked, and remove the class when un-clicked. Multiple can be selected at the same time. Right now ALL of the cities are or are not getting the class applies.
For…

user1876246
- 1,219
- 5
- 18
- 33
3
votes
1 answer
AngularJS ng-class Expression Not Working Properly?
I am using ng-repeat to list out the number of home runs vs away run in a simple table.
I am applying a class based on which team is winning using the following snippet of code:

Eoghan Buckley
- 155
- 1
- 4
- 15
3
votes
1 answer
how to get ng-class value in directive
I have some repeated 'li' elements, and some of them has 'active' class like this
in the othe hand, I have a directive to…

Behzad Shirani
- 137
- 1
- 2
- 13
3
votes
3 answers
angularjs show/hide tabs, click same tab hide the content
when i click tab A, A content show
when i click tab B, A content hide B content show
but the effect i want is when i click tab A, A content show, click A tab again content hide.
Any suggest will be help thanks
-
…

Xiao Xinqi
- 511
- 3
- 8
- 19
3
votes
3 answers
How to use $index to change class in ng-repeat?
I have a list which is limited to 3 items, the first item needs class blue1, 2nd needs blue2, 3rd blue3.
-
{{tag.term}}…

Leon Gaban
- 36,509
- 115
- 332
- 529
3
votes
1 answer
How to use ng-toggle and ng-class to change icon while using ng-click:predicate
I'm using predicate to easily sort items in my data model. Now I've working on adding in an up and down arrow icons to show which state the sort is currently in.
Example of predicate orderBy in action: http://plnkr.co/edit/?p=preview
Not sure how…

Leon Gaban
- 36,509
- 115
- 332
- 529
3
votes
2 answers
addclass if search field has value: Angularjs
I have a search input field and a listbox,
2
votes
1 answer
applying class using ng-class for nested items in Angularjs
I am displaying the menu items in the below format. The data contains list of items and for each item there is a subitem. I need to apply the selected class for the subitem selected and all other subitems for all the items should be deselected. How…

zilcuanu
- 3,451
- 8
- 52
- 105
2
votes
3 answers
ng-repeat with *conditional* ng-class by $index
I'm applying a button to a list-group-item using ng-repeat where the button has a class btn-primary when not selected and a minus glyphico and a class btn-success when selected and an ok glyphicon. I'm trying to apply this conditionally using…

b0bu
- 1,062
- 1
- 9
- 24
2
votes
2 answers
ng-switch-when and ng-class compatibility
I was wondering if there were no compatibility issues when ng-switch-when and ng-class are using on the same element like in this sample.
I'm trying to dynamically change the class of this four elements but for some reasons this isn't working on all…

Brain Up
- 163
- 2
- 10
2
votes
2 answers
How to set the ng-class in order of item clicked?
http://plnkr.co/edit/pUtuZy?p=preview
I have these 3 border classes:
.border1 {
border: 1px solid #66FFFF;
}
.border2 {
border: 1px solid #33CCFF;
}
.border3 {
border: 1px solid #0099FF;
}
I want the first button that is clicked to gain the…

Leon Gaban
- 36,509
- 115
- 332
- 529
2
votes
2 answers
Angular tab selecting using controller method
I am trying to use AngularJS to display the tab number when certain tab is selected using the controller method. It does not as expected. Greatly appreciate your help on this one.
HTML

Ming Huang
- 1,310
- 3
- 16
- 25
2
votes
1 answer
How to set class to first item in ng-repeat that has been sorted with orderBy?
I have a list of items, which comes in unsorted, I use orderBy to sort by name alphanumerically.

Leon Gaban
- 36,509
- 115
- 332
- 529
2
votes
1 answer
How to fix this ng-class toggle comparison?
http://plnkr.co/edit/7v63GXSIDon1QKm1GXCE?p=preview
I have an array which stores the name of each button that is clicked. Once clicked the object is placed into array, I use ng-class to check if the name of the object in the array is the same as the…

Leon Gaban
- 36,509
- 115
- 332
- 529