ng切换内部重复AngularJS

时间:2015-03-16 14:48:23

标签: angularjs

我想要显示

光盘1

轨道[1]

轨道[N]

Disc 2

轨道[1]

轨道[N]

我需要在哪里添加这些标题?

<h3>Track List:</h3>
<div ng-repeat="track in tracks">
  <div ng-switch on="track.disc_number">
    <div ng-switch-when="1" >
      <div>
        <div id="track">
          {{track.track_number}}) {{track.name}}
          <span>({{track.duration_ms | date : 'mm:ss'}})</span>
        </div>
      </div>
    </div>
    <div ng-switch-when="2" >
        <div id="track">
          {{track.track_number}}) {{track.name}}
          <span>({{track.duration_ms | date : 'mm:ss'}})</span>
        </div>
    </div>
  </div>
</div>

1 个答案:

答案 0 :(得分:0)

这里不需要切换。 尝试阅读ng-repeat内置filter的文档:https://docs.angularjs.org/api/ng/directive/ngRepeat

<h3>Track List:</h3>
<div ng-repeat="disc in [1, 2]">
    <h4>Disc {{disc}}</h4>
    <div ng-repeat="track in tracks | filter: {disc_number: disc}">
        <div id="track">
            {{track.track_number}}) {{track.name}}
            <span>({{track.duration_ms | date : 'mm:ss'}})</span>
        </div>
    </div>
</div>

http://plnkr.co/edit/jlycypdkSkrKj8HfcEAw?p=preview