如何按条件“切换”内容

时间:2015-07-08 09:51:29

标签: angularjs

在我的ng-repeat中,我需要根据DOM状态切换active

我试过这样,但不适合我:

<ul>

    <li ng-click="activate(item)" ng-repeat="item in items" ng-class="{active : active == item}">

          <span ng-if="item==active"> 
            <span>{{item}}</span><!-- when active nested under span -->
          </span>
          <!-- else without nesting the span -->
          <span ng-if="item== !active">{{item}}</span> //this is not working

    </li>

  </ul>

Live Demo

1 个答案:

答案 0 :(得分:2)

将您的上一个ng-if语句替换为此语句(您刚刚语法错误):

<span ng-if="item !== active">{{item}}</span>

您的active变量不是布尔值,因此您无法在语句中切换它。