Search code examples
angularjsangularjs-orderby

Order by in Angular JS


I would like to orderby below on card

<div ng-app="myApp" ng-controller="Ctrl">
    <div ng-repeat="card in myCards | orderBy:'card'">
       <businesscard>{{card}}</businesscard>
    </div>
</div>

angular.module('myApp', [])
.controller('Ctrl', function($scope) {
    $scope.myCards = ['J', 'S', 'A'];
});

The result i am expecting is, A J S

instead i am getting J S A


Solution

  • To sort by the value, simply provide no parameters to orderBy (see orderBy array item value in Angular ng-repeat):

    <div ng-repeat="card in myCards | orderBy">