1

Prior to updating Angular to 1.3, I was using Angular 1.2.

I was filtering my list of categories using this filter. What it does is remove a category that is a duplicate of what is passed in (me).

app.filter('CategorySelectFilter', function() {
    return function(cats, me) {
        var filteredCats = angular.copy(cats);
        for (var index in filteredCats) {
            if (me.id == filteredCats[index].id) {
                filteredCats.splice(index, 1);
            }
        }
        return filteredCats;
    };
});

Using this in my HTML, everything worked dandy.

ng-options="c as c.name for cat in filtered = (cats | CategorySelectFilter: cat) track by cat.id"

After updating to Angular 1.3, I started getting Infdig errors from this. I do not know what is happening.

EDIT: Added Plnkr http://plnkr.co/edit/X2cAvRyd3pdjMDOOQKfI?p=preview

It seems to work fine in the Plnkr code, but still getting Infdig errors from the console. Try comparing the code from 1.2.13 and 1.3.13 of AngularJS.

1.3.13 throws a bunch of infdig errors.

Mike
  • 826
  • 11
  • 31
  • Can you post a plnker? – Wawy Feb 27 '15 at 16:56
  • So, you are trying to remove all the duplicates from the array? – Wawy Feb 27 '15 at 17:06
  • I'm trying to put together a plnker, what I am doing is, I have a collection called cats, and I am using ng-repeat on it. Then I am going through each item in cats and giving it a list of ng-options which I remove itself from. – Mike Feb 27 '15 at 17:22

1 Answers1

1

This answer provides some cool filters to look at. If you are doing a lot of filtering maybe its easy enough to import those libs.

I created a fiddle to solve your issue.

or edited your plunker http://plnkr.co/edit/AI1O9Z?p=preview

this is how to use it.

 ng-repeat="cat in cats | catFilter:'id' "

and the filter.

app.filter('catFilter', function() {
    return function(cats, key ) {
        return cats.filter( function(elem, index, array ) { 
            return ( array.map(function(item){return item[key];}).indexOf(elem[key]) === index );
        });

    };
});
Community
  • 1
  • 1
corn3lius
  • 4,857
  • 2
  • 31
  • 36