books-list.controller.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. (function() {
  2. 'use strict';
  3. app.controller('BooksList', function($scope){
  4. $scope.sortField = 'title';
  5. $scope.books = [
  6. {
  7. title: "Harry Potter",
  8. author: "J. Rowling",
  9. date: "1970-12-12",
  10. cost: 100,
  11. rate: 5,
  12. id: 0
  13. },
  14. {
  15. title: "Potter Harry",
  16. author: "R. Jowling",
  17. date: "9999-00-00",
  18. cost: 999,
  19. rate: 10000,
  20. id: 1
  21. },
  22. {
  23. title: "Oleg Kriuchov",
  24. author: "O. Kriuchkov",
  25. date: "1993-05-03",
  26. cost: 1,
  27. rate: 0,
  28. id: 2
  29. },
  30. {
  31. title: "Хитрый Владик",
  32. author: "O. Kriuchkov",
  33. date: "2000-02-05",
  34. cost: 10,
  35. rate: 10,
  36. id: 3
  37. },
  38. {
  39. title: "Front-End for Beginers",
  40. author: "A-level",
  41. date: "2010-10-10",
  42. cost: 250,
  43. rate: 100,
  44. id: 4
  45. },
  46. {
  47. title: "How to get a million Bucks",
  48. author: "Unknown",
  49. date: "1999-01-02",
  50. cost: 1500,
  51. rate: 234,
  52. id: 5
  53. },
  54. ];
  55. $scope.deleteBook = function(id){
  56. for(var i = 0; i < $scope.books.length; i++) {
  57. if($scope.books[i].id == id) {
  58. $scope.books.splice(i, 1);
  59. }
  60. }
  61. };
  62. $scope.sortBy = function(par) {
  63. if ($scope.sortField == par) {
  64. $scope.sortField = "-"+par;
  65. } else {
  66. $scope.sortField = par;
  67. }
  68. }
  69. })
  70. })();