I want to change the background color of a div which already has a backkground color that is white for odd element and grey for even element. Dont know why its not working in Jsfiddle. The div is also having a ng-click which i have not used in JSfiddle example. I want to change the color of the div which is clicked to yellow color. Here is JsFiddle Link....LINK
Basic Code-
<div ng-app="myApp">
<div ng-controller='Ctrl'>
<div ng-repeat='item in jsonContacts' ng-style='{"left":($last?lastX:null)+"px","top":($last?lastY:null)+"px"}'>{{item}}</div>
</div>
</div>
Use ngClassOdd and ngClassEven :
ng-class-odd="'odd'" ng-class-even="'even'"
.and add 'odd' and 'even' class to your css file and it should work.
check this upadted version : http://jsfiddle.net/HB7LU/17468/
Edit : I added the change to yellow background
Your JsFiddle isn't working because it is using Angular 1.0.1 and I suspect ternary operator support wasn't implemented in expressions at that stage. This update JsFiddle only uses a newer version of Angular and your example works as is then.
Also note,
ng-repeat
also has local scope$even
and$odd
properties, similar to$index
that you can use in your calculations, e.g.You can create a method to control more over your css conditions -
Please check - http://jsfiddle.net/HB7LU/17455/
In Views -
In controllers -
There's a couple things to note here:
See a full working fiddle here: http://jsfiddle.net/HB7LU/17462/