How to sort and order array with items in AngularJS

Simple snippet how to sort and order array with items in AngularJS.

Result

JS is very simple

var app = angular.module('MoviesApp', []);
app.controller('MoviesCtrl', function($scope) {
    $scope.sortType = 'title';
    $scope.sortReverse = false;
    $scope.query = '';

    $scope.movies = [
        {title: 'The Wizard of Oz', year: 1939},
        {title: 'The Third Man', year: 1949},
        {title: 'Citizen Kane', year: 1941},
        {title: 'All About Eve', year: 1950},
        {title: 'A Hard Day\'s Night', year: 1964},
    ];
});

HTML snippet.

comments powered by Disqus