Angular js
Angular js

Reputation: 71

how to show the grouping the array of objects using angular js

I have the array of object but I don't know how to group by the id as order. I want to show it numerical order like 1,2,3 using ng-repeat

$scope.arrayofobject=[{name:"testMachne","id":1},{name:"testComputer","id":2},{name:"testCalc","id":3},{name:"testMac","id":2},{name:"testMachne","id":3},{name:"testMachne","id":1}]

Upvotes: 0

Views: 54

Answers (1)

Ankit Agarwal
Ankit Agarwal

Reputation: 30739

You can use the orderBy filter:

angular.module('app',[]).controller('mainCtrl', function($scope){
     $scope.arrayofobject=[{name:"testMachne","id":1},{name:"testComputer","id":2},{name:"testCalc","id":3},{name:"testMac","id":2},{name:"testMachne","id":3},{name:"testMachne","id":1}];
})
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app='app' ng-controller='mainCtrl'>
   
    <div ng-repeat="json in arrayofobject | orderBy:'id' " ng-if='json.id !== 1'>
       {{json.name}}
    </div>
</div>

Upvotes: 1

Related Questions