AngularJS嵌套的ng-repeat范围

时间:2014-01-25 22:26:11

标签: angularjs angularjs-ng-repeat

<div ng-repeat="store in stores">
  .. some html ..
  <div ng-repeat="item in store.items | limitTo: 50">
    ... item html ...
  </div>
  <div ng-show="store.items.length > 50">
    <button ng-click="">Show all</button>
  </div>
</div>

当有人点击按钮时,我想显示所有项目,而不仅仅是前50个。我该怎么做?如果我的控制器中有$scope.itemCount = 50,那么这将适用于所有商店和所有商品。我希望它只适用于store.items的范围。

任何帮助?

1 个答案:

答案 0 :(得分:2)

试试这个:

<div ng-repeat="store in stores" ng-init="storeCount = itemCount">
  .. some html ..
  <div ng-repeat="item in store.items | limitTo: storeCount">
    ... item html ...
  </div>
  <div ng-show="store.items.length > storeCount">
    <button ng-click="storeCount = store.items.length">Show all</button>
  </div>
</div>