books-list.controller.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. (function () {
  2. 'use strict';
  3. app.controller('BooksList', function($scope) {
  4. console.log("OK");
  5. $scope.sortField = 'index';
  6. $scope.sortBy = function(field) {
  7. $scope.sortField = ($scope.sortField === field) ? '-' + field : field;
  8. }
  9. $scope.deleteBook = function(bookId) {
  10. function findBookId(element, index, array) {
  11. if (element.id === bookId) return true
  12. }
  13. var index = $scope.books.findIndex(findBookId);
  14. $scope.books.splice(index, 1);
  15. }
  16. $scope.books = [
  17. {
  18. id: 0,
  19. title: "Harry Potter",
  20. author: "J. ROwling",
  21. date: "1970-01-01",
  22. cost: 100,
  23. rate: 1.2
  24. },
  25. {
  26. id: 1,
  27. title: "Harry COMPUTER",
  28. author: "J. ROwling",
  29. date: "1970-01-01",
  30. cost: 99,
  31. rate: 2.4
  32. },
  33. {
  34. id: 2,
  35. title: "Harry LIGTER",
  36. author: "Git. Bash",
  37. date: "2026-05-15",
  38. cost: 5,
  39. rate: 1
  40. },
  41. {
  42. id: 3,
  43. title: "Berry Potter",
  44. author: "M. Bower",
  45. date: "1950-01-01",
  46. cost: 88,
  47. rate: 3
  48. },
  49. {
  50. id: 4,
  51. title: "Adam Potter",
  52. author: "V. NPM",
  53. date: "1870-01-01",
  54. cost: 24,
  55. rate: 3.2
  56. },
  57. {
  58. id: 5,
  59. title: "The Things We Don't Say",
  60. author: "Carey, Ella",
  61. date: "2010-15-01",
  62. cost: 42,
  63. rate: 1.1
  64. },
  65. {
  66. id: 6,
  67. title: "Невеста Мрачнейшего",
  68. author: "Лилия Лисовская",
  69. date: "2018-05-21",
  70. cost: 55.6,
  71. rate: 5
  72. }
  73. ];
  74. });
  75. })();