0

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}]
1
  • What is your expected output? Commented Sep 24, 2017 at 5:25

1 Answer 1

1

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>

Sign up to request clarification or add additional context in comments.

2 Comments

thanks for the help.if i want to show the id 2 as in first position and 3 as second positon and so on.what could i do for this
you can use a condition in ng-repeat . Check my updated answer

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.