How to filter with ANGULAR JS not to repeat the same names?

7

I have 2 related tables in the bank: The first table: if it is called restaurant the other Table: Cardapio. The Cardapio Table receives the primary key from the restaurant, so it becomes foreign until then, I get this information from the bank with an Api Php + Mysql I do the inner Join of the 2 tables and I get a Json: So I get this data with my Controller Angular Js and game for my view where I use Ng-repeat until all right it lists the names of Restaurants only that unfortunately repeats the names. Example I have a Restaurant in the Bank with Name of BABYS Gula if I go to the table menu and register 3 snacks for this restaurant the name of this Restaurant in my List repeats 3 times and repeats itself for those of more restaurants registered.

insert the image description here

    
asked by anonymous 08.07.2016 / 21:16

1 answer

5

You can use AngularUI to resolve this issue.

Example:

var myApp = angular.module('myApp', ['ui.filters']);

function MyCtrl($scope) {
$scope.names = [{
    id: 1,
    Name: 'Diego'
}, {
    id: 2,
    Name: 'Bruno'
}, {
    id: 3,
    Name: 'Diego'
}]
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script><scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/angular-ui/0.4.0/angular-ui.js"></script>

<div ng-app="myApp" ng-controller="MyCtrl">
  <ul ng-repeat="item in names | unique: 'Name' ">
    <li>{{item.Name}}</li>
  </ul>
</div>

Note that after installing the lib, just use the unique filter on your ng-repeat and choose which field should be unique:

ng-repeat="item in names | unique: 'Name' 
    
08.07.2016 / 21:47