本文介绍了AngularJS:如何更改基于变NG-重复limitTo?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想显示在Angular.js NG重复不同的limitTo数的基础上,一个变量。

I would like to show a different limitTo number on Angular.js ng-repeat, based on a variable.

下面是我的code:

<input type="text" ng-model="search" ng-change="checkNewCard(search)"/>
<div ng-repeat="score in scores | filter:search | limitTo:6" ng-hide="search">
...
</div>
<div ng-repeat="score in scores | filter:search | limitTo:5" ng-hide="!search">
...
</div>
<div new-card name="search" ng-show="showNewCard"></div>

和在控制器:

$scope.showNewCard = false;
$scope.checkNewCard = function (search) {
if (search == "")
    $scope.showNewCard = false;
else {
    $scope.showNewCard = true;
    }
};

我只能假设有基于搜索输入改变limitTo更优雅的方式,我只是不知道要寻找什么。

I can only assume there is a more elegant way of changing the limitTo based on the search input, I just have no idea what to look for.

您可以看到这个code对的实施。
搜索结果
附:
我在这里新的,新的总体发展,所以请原谅我,如果这个问题没有正确的问道。搜索结果
提前感谢!

You can see the implementation of this code on http://happinesshunt.co.

P.S.I'm new here and new to development in general, so please forgive me if the question wasn't asked properly.

Thanks ahead!

推荐答案

下面可以是第一溶液(因为它可以改善,例如通过隐藏/显示更多/更少的链接):

Here could be a first solution (since it can be improved, e.g. by hiding/displaying the more/less links):

<div ng-repeat="score in scores | limitTo: limit">
...
</div>
<a href ng-click="incrementLimit()">more</a>
<a href ng-click="decrementLimit()">less</a>

在你的控制器:

var limitStep = 5;
$scope.limit = limitStep;
$scope.incrementLimit = function() {
    $scope.limit += limitStep;
};
$scope.decrementLimit = function() {
    $scope.limit -= limitStep;
};

这篇关于AngularJS:如何更改基于变NG-重复limitTo?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 12:15