(function() { 'use strict'; app.controller('BooksList', function($scope){ $scope.sortField = 'title'; $scope.books = [ { title: "Harry Potter", author: "J. Rowling", date: "1970-12-12", cost: 100, rate: 5, id: 0 }, { title: "Potter Harry", author: "R. Jowling", date: "9999-00-00", cost: 999, rate: 10000, id: 1 }, { title: "Oleg Kriuchov", author: "O. Kriuchkov", date: "1993-05-03", cost: 1, rate: 0, id: 2 }, { title: "Хитрый Владик", author: "O. Kriuchkov", date: "2000-02-05", cost: 10, rate: 10, id: 3 }, { title: "Front-End for Beginers", author: "A-level", date: "2010-10-10", cost: 250, rate: 100, id: 4 }, { title: "How to get a million Bucks", author: "Unknown", date: "1999-01-02", cost: 1500, rate: 234, id: 5 }, ]; $scope.deleteBook = function(id){ for(var i = 0; i < $scope.books.length; i++) { if($scope.books[i].id == id) { $scope.books.splice(i, 1); } } }; $scope.sortBy = function(par) { if ($scope.sortField == par) { $scope.sortField = "-"+par; } else { $scope.sortField = par; } } }) })();