Ionic and Angularjs: How to filter repeated names in ngRepeat

Asked

Viewed 119 times

2

How to filter, with Ionic and Angularjs, repeated names in my ng-repeat? I’ve used the ui.filters and the unique only works when there are no routes, ie on Websites in mobile applications does not work.

On my controller I tried that:

angular.module('myApp', ['ui.filters'])
       .controller("papaRoca", function($scope, Data, $location) { });

And in my view placed:

<div ng-repeat="Lista in Listas | unique:'nome'">...</div>

Can someone help me?

  • it would help if you put part of the code of what you’ve already done.

  • Leo in my controller tried that angular.module('myapp', ['ui.Filters']) . controller("paparoca", Function($Scope, Data, $Location) { }); and in my vein put <ng-repeat = List in Lists | Unique:'name'>

  • 1

    @Dan100, add the parts of the code directly to your question, and not in the comments.

  • @Dan100, as it is an object that is coming in Listas?

  • 1

    Take a look at this reply. Must have what you need.

  • Dude, I’m using ui.Filters on a system full of routes and it’s normal.

  • Diego you use with normal Ionic ?

  • Hi, Use this plugin: https://github.com/a8m/angular-filter here you can use | Unique:'field that you want' without creating anything in the controller. ;)

Show 3 more comments

1 answer

0

app.filter('unique', function() {

  return function (arr, field) {
    var o = {}, i, l = arr.length, r = [];
    for(i=0; i<l;i+=1) {
      o[arr[i][field]] = arr[i];
    }
    for(i in o) {
      r.push(o[i]);
    }
    return r;
  };
})

try this function.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.