0

是否有任何选项可以像这样放置 $last ng-repeat 结果<li class="active">Four</li>而不是<li><a href="#">Four</a></li>?我一直在尝试,ng-if但不幸的是它还没有给出好的解决方案:(

演示:http ://codepen.io/anon/pen/bdvVRe

var app = angular.module('myapp', []);
app.controller('testController', function($scope) {
  $scope.mymenu = ["one", "two", "three", "four"];
});
<link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="myapp">
  <div ng-controller="testController" class="container">
    <strong>Expecting</strong>
    <br />
    <ol class="breadcrumb">
      <li><a href="#">One</a></li>
      <li><a href="#">Two</a></li>
      <li><a href="#">Three</a></li>
      <li class="active">Four</li>
    </ol>
    <hr />
    <strong>Current result</strong>
    <ol class="breadcrumb">
      <li ng-repeat="menu in mymenu"><a href="#">{{menu}}</a></li>
    </ol>
  </div>
</div>

4

1 回答 1

4
<li ng-repeat="menu in mymenu" ng-class="{active: $last}">
    <a ng-if="!$last" href="#">{{menu}}</a>
    <span ng-if="$last">{{menu}}</span>
</li>

演示:http ://codepen.io/anon/pen/domYZL

于 2015-07-05T16:24:45.710 回答