简体   繁体   中英

Angular js ng repeat with conditional ng class not applying css class

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

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;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM