Angularjs:自定义角度过滤器导致无限循环

时间:2015-09-29 20:10:00

标签: angularjs ionic-framework ionic

在我的Ionic应用程序中,我在filter.js文件中创建了一个自定义过滤器“partition”(见下文)。

我试图在模板中使用它,但是我得到了一个rootcope错误: 错误:[$ rootScope:infdig] http://errors.angularjs.org/1.2.25/ $ rootScope / infdig?p0 = 10& p1 =%5B%5B%22fn%3 ... inder%20Max%20-%20Keely%20Andrew%5C%22%3B% 20oldVal%3A%20undefined%22%5D%5D

你可以帮我解决这个问题吗?

由于

模板result.html:

<ion-slide-box show-pager="true" does-continue="true" on-slide-changed="slideHasChanged($index)">
            <ion-slide ng-repeat="batch in prodata | partition:8 track by $index">
                <ul>
                    <li ng-repeat="item in batch track by $index">
                        <a class="suggestPro" href="#">
                            <span><img ng-src="img/boards/{{item.imageName}}" /></span>
                            <p class="flex-caption"> {{item.model}} - {{item.name}}</p>
                        </a>
                    </li>
                </ul>
            </ion-slide>
        </ion-slide-box>

app.js:

angular.module('BoardLine', ['ionic', 'ngCookies', 'ui.unique', 'BoardLine.controllers', 'BoardLine.services', 'BoardLine.filters'])

filter.js:

angular.module('BoardLine.filters', [])

.filter('nospace', function() {
    return function (value) {
        return (!value) ? '' : value.replace(/ /g, '');
    };
})

.filter('partition', function() {
    return function(array, size) {
        var newArray = [], i, next;

        for(i = 0; i < array.length; i = next) {
            next = i + size;
            newArray.push(array.slice(i, next));
        }

        return newArray;
    };
});

1 个答案:

答案 0 :(得分:0)

实现此结果的另一种解决方案,没有分区&#39;过滤,并使用limitTo

    <ion-slide-box show-pager="true" does-continue="true" on-slide-changed="slideHasChanged($index)">
        <ion-slide ng-repeat="s in [0,1,2,3,4,5,6]">
            <ul>
                <li ng-repeat="item in prodata | matchingProBrand:computed.proName:computed.proBrand | limitTo:s*8+8  | limitTo:-8">
                    <a class="suggestPro" ng-click="launchComputeService(item.id)">
                        <span><img ng-src={{imagesUrls[item.imageName]}} /></span>
                        <p class="flex-caption"> {{item.model}} - {{item.name}}</p>
                    </a>
                </li>
            </ul>   
        </ion-slide>

    </ion-slide-box>