Hitu Bansal
Hitu Bansal

Reputation: 3137

ng-class in Angular js

I need this html

<div>
    <div>1</div>
    <div>2</div>
    <div>3</div>
    <div class="last">4</div>

    <div>5</div>
    <div>6</div>
    <div>7</div>
    <div class="last">8</div>    
<div>

I am using this function

<div class="col-md-3"
     ng-repeat="items in data.data"
     data-ng-class="{'last': $index%3 == 0 && $index!=0}"  >

But i m getting this output

<div>
    <div>1</div>
    <div>2</div>
    <div>3</div>
    <div class="last">4</div>

    <div>5</div>
    <div>6</div>
    <div class="last">7</div>
    <div>8</div>

<div>

Upvotes: 0

Views: 50

Answers (2)

Hitu Bansal
Hitu Bansal

Reputation: 3137

Finally i got the solution

{'last': ($index+1) % 4 == 0 && $index!=0}

@Ben Black comments helped me.

Edit suggested {'last': ($index+1) % 4 == 0 } because $index never be zero This solution might help others

Upvotes: 0

user1907906
user1907906

Reputation:

Use 4, not 3 if you want the rows with index divisible by four.

{'last': ($index + 1 ) % 4 == 0 && $index != 0}

Upvotes: 1

Related Questions