ng-class-甚至不申请课程

时间:2014-09-02 17:50:18

标签: angularjs angularjs-ng-repeat

所以我正在尝试斑马条纹ng-repeat,以便可以轻松区分行。

我认为我已正确连接所有内容,但这些类尚未应用。

我创建了plunker here

我的HTML看起来像这样:

<div ng-repeat="removal in removals" ng-class-even="even" ng-class-odd="odd" class="remove-relation-titles-list">
      <div class="pull-left relation-titles-left-list">
           <span class="acct-title acct-num">{{removal.AcctType}} {{removal.AcctNo}}</span>
           <span class="acct-title"> - Standard Checking</span>
      </div>
</div>

所以,常规课程应用得很好,但偶数和奇数课程都没有。如果你检查对象并自己添加even类,它会很好地显示出来。我已尝试将其移至div内的ng-repeat,但没有结果。

我错过了一些明显的东西吗?

2 个答案:

答案 0 :(得分:9)

将您的ng-class更改为: -

ng-class="{'even':$even,'odd':$odd}"

<强> Plnkr

$even$odd是ng-repeat在其范围内添加的属性。

或将其更改为string value of the class names,否则会尝试根据不存在的属性evenodd替换该类: -

ng-class-odd="'odd'" ng-class-even="'even'"

答案 1 :(得分:2)

<!DOCTYPE html>
<html>

  <head>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.17/angular.min.js" data-semver="1.2.17" data-require="angular.js@1.0.7"></script>
    <link rel="stylesheet" href="style.css" />
    <script src="script.js"></script>
  </head>

  <body ng-app="myApp">
    <div ng-controller="removeTitlesCtrl">
      <div id="body_content_wrapper">
        <div>
          <h4 class="heading toggle header-block">These are the accounts chosen</h4>
        </div>
        <div ng-repeat="removal in removals" ng-class-even="'even'" ng-class-odd="'odd'" class="remove-relation-titles-list">
          <div class="pull-left relation-titles-left-list">
            <span class="acct-title acct-num">{{removal.AcctType}} {{removal.AcctNo}}</span>
            <span class="acct-title"> - Standard Checking</span>
          </div>
        </div>
      </div>
    </div>
  </body>

</html>

这是一个简单的错误,请更正。

ng-class-even="'even'" ng-class-odd="'odd'"