1

here is my code , i dont know what mistake i am doing??? Is there a built in filter or function to sort array of integers or numbers??

<body data-ng-app="app" data-ng-controller="controller1" >
  <div class="container">
    <div class="row">
        <input type="text" ng-model="searchbox" />

        <li ng-repeat="num in numbers|filter:searchbox|orderBy:number">
            {{num}}
        </li>
    </div>
  </div>  

  <script type="text/javascript">
    var app=angular.module('app', []).controller('controller1', ['$scope', function($scope){


      $scope.numbers=[10,8,6,7];

       $scope.number=function(data)
       {
        return data.sort();
       }

    }


    ]);
  </script>

</body>

1 Answer 1

2

Check out this answer orderBy array item value in Angular ng-repeat

This means that you can do something like this:

app.controller('ctrl', ['$scope', function($scope){
   $scope.numbers = [10,8,6,7];
   $scope.identity = angular.identity;
}]);

And

<li ng-repeat="num in numbers | orderBy:identity">
   {{num}}
</li>
Sign up to request clarification or add additional context in comments.

Comments

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.