Javascript 角度,通过布尔值切换Limito(自定义Limito?)

Javascript 角度,通过布尔值切换Limito(自定义Limito?),javascript,angularjs,Javascript,Angularjs,所以我试图在Limito上实现一种切换效果,在角度上有一个预定义的量。我的意思是,输入的数据上有一个布尔值“showMore”。如果是真的,我的重复次数将限制在5次,否则就没有限制了。我想知道解决这样一个问题的最好方法是什么?所以我有这个重复的例子: <div ng-repeat="item in filter.values track by $index" class="builder-result-filter-value checkbox" value="item" update-

所以我试图在Limito上实现一种切换效果,在角度上有一个预定义的量。我的意思是,输入的数据上有一个布尔值“showMore”。如果是真的,我的重复次数将限制在5次,否则就没有限制了。我想知道解决这样一个问题的最好方法是什么?所以我有这个重复的例子:

 <div ng-repeat="item in filter.values track by $index" class="builder-result-filter-value checkbox" value="item" update-filter="updateFilter">
所以我想让这个布尔值来控制它是重复使用limito:5,还是完全没有限制

我想到了一种方法来做类似的事情

 <div ng-if="filter.showMore" ng-repeat="item in filter.values track by $index | limitTo: limitValue">
 <div ng-if="!filter.showMore" ng-repeat="item in filter.values track by $index">


但我认为必须有一种更优雅的方式。如有任何建议/意见,将不胜感激。谢谢

您可以尝试在控制器内执行该逻辑。大概是这样的:

if (filter.showMore) {
    $scope.limitValue = 5;
else {
    $scope.limitValue = null;
}
<div ng-repeat="item in filter.values track by $index | limitTo: limitValue">
您的html将如下所示:

if (filter.showMore) {
    $scope.limitValue = 5;
else {
    $scope.limitValue = null;
}
<div ng-repeat="item in filter.values track by $index | limitTo: limitValue">

如果,则无需使用
ng。您可以在HTML本身上使用
limitTo
中的表达式,比如
limitTo:filter.showMore?limitValue:filter.values.length

标记

<div ng-repeat="item in filter.values | limitTo: filter.showMore ? limitValue: filter.values.length track by $index">