4

I have a ng repeat with a ng class that doesn't apply the css class in the case where my css class has a hyphen in the name:

<li
  ng-repeat="item in items"
  ng-class="{'i-someclass' : item.Id > 10}">
  {{item .name}}
</li>

Am I doing anything wrong? If I change the css class name to isomeclass it works. AngularJS v1.0.7

1
  • Just check if angular is adding a class named iSomeclass. Commented Dec 10, 2013 at 10:39

1 Answer 1

9

For me, your code works as is.

Here is a plunker that demonstrates the code.

js:

var app = angular.module('myApp', []);

app.controller('Ctrl', function($scope) {

  $scope.items = [

    { Id: 1, name: "item1" },
    { Id: 10, name: "item1" },
    { Id: 11, name: "item1" }
    ];

  });

html:

<html ng-app="myApp">

  <head>
    <script data-require="angular.js@*" data-semver="1.2.4" src="http://code.angularjs.org/1.2.4/angular.js"></script>
    <link rel="stylesheet" href="style.css" />
    <script src="script.js"></script>
  </head>

  <body ng-controller="Ctrl">
    <h1>Hello Plunker!</h1>
    <ul>
      <li
        ng-repeat="item in items"
        ng-class="{'i-someclass' : item.Id > 10}">
        {{item .name}}
      </li>
    </ul>
  </body>

</html>

css:

.i-someclass {
  color: red;
}
Sign up to request clarification or add additional context in comments.

3 Comments

I think he is specifically talking about the verion 1.0.7 so the issue maybe in that version.
@Chandermani Ok, I updated the plunker link (it now is 1.0.7) and still works. :)
hi sorry for the long wait to reply, it does work on a simple controller, my description lacked a bit, I am using this code within a partial, so we have data-ng-include data-src="getMyPartial()" data-ng-show="getMyPartial()". getMyPartial is a method on the scope that loads the partial in, so I think the issue is when the above code is loaded in this manner through a partial.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.