Angularjs repeat do every 2nd time

So I wanted to do something in AngularJS for every 2nd item in my ng-repeat. I’m using Bootstrap’s rows and columns so I wanted to get some padding in between them without using an offset.

angularjs repeat do every 2nd time

I’m just using col-md-6 which splits the row into 2 columns at 50%. So I need to add a class for each item on the li so it knows if it’s first or second item basically.

So then I found Angular provides such a directive already! It’s called ngClassOdd. So I added thes attributes to my list items and hey presto!

If we inspect it, we can see it’s adding the correct class to our DOM elements.

If we inspect it, we can see it's adding the correct class to our DOM elements.

And with the styles (I’m using LESS) I get my gap!

finished result angularjs

Sam is a passionate web developer, online entrepreneur and investor. In his spare time he enjoys coding, playing chess and reading.

Leave a Reply

Your email address will not be published. Required fields are marked *