Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8530491
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T09:15:32+00:00 2026-06-11T09:15:32+00:00

I need to apply a different class to a <tr> according to the $index

  • 0

I need to apply a different class to a <tr> according to the $index of the repeat directive. For example

<table>
   <tr ng-repeat="model in list" class="xxx">
       <td>...</td>
   <tr>
</table>

I need to apply a different style to <tr> depending on whether the index is even and odd.

How could I solve this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T09:15:34+00:00Added an answer on June 11, 2026 at 9:15 am

    Normally you would use ngClassOdd (http://docs.angularjs.org/api/ng.directive:ngClassOdd) and ngClassEven (http://docs.angularjs.org/api/ng.directive:ngClassEven) directives like this:

    <tr ng-repeat="item in items" ng-class-odd="'class1'" ng-class-even="'class2'">
    

    Here is the jsFiddle: http://jsfiddle.net/pkozlowski_opensource/hNHJ4/1/

    Unfortunately there is an issue where the mentioned directives are not working correctly when rows are removed: https://github.com/angular/angular.js/issues/1076

    As a work around you can use the ngClass directive (http://docs.angularjs.org/api/ng.directive:ngClass) with the $index variable exposed by a repeater:

    <tr ng-repeat="item in items" ng-class="{class1 : $index%2==0, class2 : !($index%2==0)}">
    

    Here is the jsFiddle: http://jsfiddle.net/pkozlowski_opensource/am7xs/

    It is not super-clean, but could be improved (for example, by exposing a function in a root scope, something like:

    ng-class="getClass($index,'class1','class2')"
    

    till the mentioned bug is fixed

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to apply/remove to an input field according to a user's selection in
I need to apply a style on a recurring element which has a fixed
I need to apply a class to the post archive links that are output
I've got a tr:table that I need to style using CSS. All the normal
I have a class with all different kinds of data members, including a list
I need to style the first and last items of a list view differently.
Need to apply a filter to a file like this: TUPAC_0006:1:1:2554:2356#0/1 0 * 0
I need to apply tint effect on image in Android . But the tint
I need to apply validation on input time intervals that are taken in as
I need to apply paragraph formatting to a selection in a rich text box.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.