http://plnkr.co/edit/6AEvKuyXai9LbcNjfluN?p=preview

我有3个链接,第一个有.active类。当您单击2和3时,数字1应该会丢失.active类。现在,如果您单击2或3,它们将正确更新,但是1上仍然有活动的类:(

<ul>
  <li class="active"
      data-ng-class="{'active' : toggleObject == 1}"
      data-ng-click="toggleObject = 1">a click 1
  </li>
  <li data-ng-class="{'active' : toggleObject == 2}"
      data-ng-click="toggleObject = 2">a click 2
  </li>
  <li data-ng-class="{'active' : toggleObject == 3}"
      data-ng-click="toggleObject = 3">a click 3
    <br>
  </li>
</ul>

最佳答案

您需要从第一个li中删除该类,而是在控制器中将toggleObject设置为1。

function HolaCtrl($scope){
  $scope.toggleObject = 1;
}

<li data-ng-class="{'active' : toggleObject == 1}" data-ng-click="toggleObject = 1">a click 1<br>
</li>
<li data-ng-class="{'active' : toggleObject == 2}" data-ng-click="toggleObject = 2">a click 2
<br>
</li>
<li data-ng-class="{'active' : toggleObject == 3}" data-ng-click="toggleObject = 3">a click 3
        <br>
</li>

09-26 04:42