ADZ 學習筆記

Ruby/Rails, Startup, Life

[AngularJS] ng-class 條件判斷

| Comments

ng-class 判斷條件

  1. 方式一 (如果成立則使用某 class)

    範例 jsfiddle.net

pages.html
<ul>
    <li ng-repeat="i in [1, 2, 3, 4, 5]" ng-class="{'currentPageClass': page == currentPage}">
          <!-- condition true: class="currentPageClass" -->
    </li>
</ul>
  1. 方式二 (成立、失敗使用個別 class)

    範例 jsfiddle.net

pages.html
<ul ng-init="liClassMapper = {true:'selected', false:'unselected'};">
    <li ng-repeat="i in [1, 2, 3, 4, 5]" ng:class="liClass[index > 2]">
          <!-- condition true: class="selected", false: class="unselected" -->
    </li>
</ul>

Comments

comments powered by Disqus