0

I'm trying to display information grouped by address. For some reason orderBy and groupBy not working.

This is my view:

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js">     </script>
 <div ng-app="app" ng-controller="ctrl">
   <div ng-repeat="item in data  | orderBy:'address' | groupBy:'address' " >
      <h5 ng-click="toggle_visibility(item);">{{item.address}}</h5>
         <div ng-hide="item.hideAddress">
            <ul>
              <li>First Name: {{item.firstname}}  </li>
           </ul>
        </div>
    </div>
 </div>

This is my controller:

angular.module("app",[])
.controller("ctrl",function($scope){
$scope.data = [
    {
        firstname: "user",
        address: "address1",

    },
    {
        firstname: "user1",
        address: "address1",

    },
    {
        firstname: "user2",
        address: "address3",

    }
];

$scope.toggle_visibility = function(item){
   item.hideAddress = !item.hideAddress;
}

})

When I add groupBy and run it, I get no data at all to display but if I remove groupBy I'll get the groups by address but 2 groups with the same address name. How can I fix it please?

  • 1
    Take a look at this: http://stackoverflow.com/questions/14800862/how-can-i-group-data-with-an-angular-filter – yBrodsky Mar 09 '17 at 15:39
  • 1
    You should take a look at [this answer](http://stackoverflow.com/a/30866092/3233827). – ssc-hrep3 Mar 09 '17 at 15:39
  • 1
    Possible duplicate of [Angularjs groupBy + orderBy](http://stackoverflow.com/questions/28473736/angularjs-groupby-orderby) – ssc-hrep3 Mar 09 '17 at 15:39

0 Answers0