跳过ng-repeat中的第一项

nam*_* vo 46 angularjs

我想跳过ng-repeat中的第一项

..first item here  

<ul class="highlight-topright">
        <li ng-repeat="item in hpHeadlines | filter:$index>0">
          ...
        </li>
</ul>
Run Code Online (Sandbox Code Playgroud)

它不起作用,这里有什么不对吗?

据我所知,我可以使用ng-if,ng-show隐藏内容,但我无法理解为什么在这种情况下过滤器在1.3.x中不起作用.

谢谢.

dha*_*ngg 77

<ul class="highlight-topright">
        <li ng-repeat="item in hpHeadlines" ng-if="$index > 0">
          ...
        </li>
</ul>
Run Code Online (Sandbox Code Playgroud)

  • 另一种选择是`ng-if ="!$ first"`. (33认同)

Ved*_*Ved 32

首先使用$ first:

<ul class="highlight-topright">
        <li ng-repeat="item in hpHeadlines" ng-hide="$first">
          ...
        </li>
</ul>
Run Code Online (Sandbox Code Playgroud)

要么,

  <ul class="highlight-topright">
            <li ng-repeat="item in hpHeadlines" ng-if="!$first">
              ...
            </li>
    </ul>
Run Code Online (Sandbox Code Playgroud)


Jac*_*hea 13

您还可以使用limitTo过滤器.

作为负索引,begin表示从输入结束的偏移量.默认为0.

<li ng-repeat="item in hpHeadlines | limitTo: 1 - hpHeadlines.length">
  ...
</li>
Run Code Online (Sandbox Code Playgroud)