Angular ng-repeat reverse Example – reverse filter

Angular ng-repeat reverse Example – reverse filter

Ref: AngularJS orderBy Reverse Example

An orderBy keywords used to Filter in AngularJS sorts simple an array of data. config : The default behavior of an simple orderBy is Ascending order Means false, be it a string simple changes true or an integer data.Angular ng-repeat reverse Example – reverse filter

Syntax of reverse filter

{{ orderBy_expression | orderBy : expression : reverse}}

angular ng-repeat in reverse Example

<div ng-repeat="cat in posts | reverse">{{cat.name}}</div>

app.filter('reverse', function() {
  return function(products) {
    return products.slice().reverse();
  };
});

Angularjs orderby reverse Object print Example

I am going to display we how to sort all the Data extracted from JSON dataand array and show the all the data in Descending order By using ng-repeat directives orderBy Filter.Sorting by all the json Multiple Fields with Different type of Sort Orders Using the AngularJS used to orderby Filter

READ :  Angular RESTful API CRUD Application

<tr ng-repeat="cat in posts | orderBy:'$index':true">

angularjs – Reverse list in ng-repeat Example

<!doctype html>
<html ng-app="liveApp">
<head>
    <script src="jquery-1.9.1.min.js"></script>
    <script src="angular.min.js"></script>
    <script>
    angular.module('liveApp', []).controller('Ctrl', function($scope) {
        $scope.products = [1, 2, 3, 4];
        $scope.reverse = function(array) {
            var copy = [].concat(array);
            return copy.reverse();
        }
    });
    </script>
</head>
<body ng-controller="Ctrl">
    <ul>
        <li ng-repeat="product in products">{{product}}</li>
    </ul>
    <ul>
        <li ng-repeat="product in reverse(products)">{{product}}</li>
    </ul>
</body>
</html>

Descending order by date filter in AngularJs

<div class="livec" ng-repeat="bk in    (productItems = (book.bk | orderBy: 'created_at':true | limitTo: 1))">
</div>

in controller
------------
filter:orderBy(array, expression[, reverse]);


Example

angularjs table reverse ng-repeat example

index.html

<div ng-app>
    <div ng-controller="liveCtrl">
        <ul ng-repeat="item in posts | orderBy:'srno':true">
            <li>{{item.srno}} :: {{item.web}}</li>
        </ul>
    </div>
</div>

Script.js
function liveCtrl($scope) {
    $scope.posts = [
        {web: 'a', srno: 1},
        {web: 'b', srno: 2},
        {web: 'c', srno: 3},
    ];
}

orderBy multiple fields in Angular Example

post : Sub-post
1 – 1
1 – 2
1 – 20
2 – 1
2 – 10
2 – 11

READ :  Angular dependable Country State City Cascading DropDownList

<div ng-repeat="stud in students | orderBy:['post','sub']">{{stud.post}}-{{stud.sub}}</div>

json

$scope.students = [{'post':1,'sub':1}, {'post':2,'sub':10}, {'post':1,'sub':2},{'post':1,'sub':20},{'post':2,'sub':1},
    {'post':2,'sub':11}];

Example

Add a Comment

Your email address will not be published. Required fields are marked *