books-list.controller.js 1.3 KB

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