简体   繁体   中英

ng-repeat; different outfor for final element

I'm working on making a basic breadcrumb trail (using bootstrap) that will help users navigate out site. Using AngularJS, I've created a modal of a map that gives options of where they can go based on the data they're currently looking at.

To help our users remember where they got there (and how to get back), the breadcrumb is appended each time they drill through the data.

I have have the following snippet:

<ol class="breadcrumb">
    <li ng-repeat="item in items" ng-switch on="$last">
        <div ng-switch-when="false">
            <a href="#">{{item}}</a> <span class="divider"> > </span>
        </div>
        <div ng-swtich-when="true">
            {{item}}
        </div>
    </li>
</ol>

but it produces some funky output. I get the following output:

<ol class="breadcrumb">
    <li class="ng-scope" on="$last" ng-switch="" ng-repeat="item in items">
        <div class="ng-binding" ng-swtich-when="true"> University </div>
        <div class="ng-scope" ng-switch-when="false">
            <a class="ng-binding" href="#">University</a>
            <span class="divider"> > </span>
        </div>
    </li>
    <li class="ng-scope" on="$last" ng-switch="" ng-repeat="item in items">
        <div class="ng-binding" ng-swtich-when="true"> College of Engineering </div>
        <div class="ng-scope" ng-switch-when="false">
             <a class="ng-binding" href="#">College of Engineering</a>
             <span class="divider"> > </span>
        </div>
    </li>
    <li class="ng-scope" on="$last" ng-switch="" ng-repeat="item in items">
        <div class="ng-binding" ng-swtich-when="true"> Environmental Engineering </div>
    </li>
</ol>

Which looks like:

呈现的HTML

Is there something going on with the previous content not being removed on redraw? Or do I need a better method for this case than the switch?

错字..您想要ng-switch-when而不是ng-swtich-when

<div ng-swtich-when="true">

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM