简体   繁体   English

在ng-repeat内过滤angularjs

[英]Filtering in angularjs inside ng-repeat

im trying to filter inside a ngRepeat and i'm getting always the same error with all filters using filter , here i put the code and the error: 即时尝试在ngRepeat内部进行过滤,并且我在使用filter所有过滤器时总是得到相同的错误,这里我把代码和错误:

HTML: HTML:

<input type="text" ng-model="searchOd.name"/>
<li ng-repeat="od in opdata[odTag] | filter:searchOd as odFiltered">

Error: 错误:

TypeError: boolean is not a function
at angular.min.js:16709
at $parseFilter (angular.min.js:12155)
at Object.regularInterceptedExpression (angular.min.js:12851)
at Scope.$get.Scope.$digest (angular.min.js:14235)
at Scope.$get.Scope.$apply (angular.min.js:14506)
at done (angular.min.js:9659)
at completeRequest (angular.min.js:9849)
at XMLHttpRequest.requestLoaded (angular.min.js:9790)

I try to export opdata[odTag] using {{opdata[odTag] | 我尝试使用{{opdata [odTag] |导出opdata [odTag] json}} and put in in a plunkr but in plunkr it works!! json}}并且放入一个plunkr但是在plunkr它工作! what i'm doing wrong? 我做错了什么?

This is how i'm doing now without filter : 这就是我现在没有filter

.filter('byDistrict', function() {
    return function(items, id_district) {
        var filtered = [];
        if(!id_district) return items;
        angular.forEach(items, function(item) {
            if(item.id_district == id_district) filtered.push(item);
        });
        return filtered;
    }
})

Thanks in advance! 提前致谢!

EDIT: 编辑:

As is said in the plunkr it works but i put here: plunkr 正如在plunkr中说的那样它可以工作,但我放在这里: plunkr

Nothing wrong with your code. 您的代码没有错。 But you are using Angular 1.2.x where the "as results" feature is part of Angular 1.3+ 但是你使用的是Angular 1.2.x,其中“as results”功能是Angular 1.3+的一部分

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM