-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
65 lines (39 loc) · 1.42 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
var app = angular.module("app", ['ngRoute']);
const api_url = 'http://127.0.0.1:8000';
app.controller('ListCtrl', function ($scope, $http, $location) {
$http.get(api_url + '/book').then(function (data) {
$scope.books = data.data;
});
$scope.delete = function (book) {
var deletebook = confirm('Are you absolutely sure you want to delete?');
if (deletebook) {
$http.delete(api_url + '/book/' + book.id);
var index = $scope.books.indexOf(book);
$scope.books.splice(index, 1);
$scope.activePath = $location.path('/');
}
};
});
app.controller('EditCtrl', function ($scope, $http, $location, $routeParams) {
var id = $routeParams.id;
$scope.activePath = null;
$http.get(api_url + '/book/' + id).then(function (data) {
$scope.book = data.data;
});
$scope.update = function (book) {
$http.put(api_url + '/book/' + id, book).then(function (data) {
$scope.book = data;
$scope.activePath = $location.path('/');
});
};
});
app.controller('AddCtrl', function ($scope, $http, $location) {
$scope.master = {};
$scope.activePath = null;
$scope.add = function (book, AddForm) {
$http.post(api_url + '/book', book).then(function () {
$scope.activePath = $location.path('/');
});
$scope.activePath = $location.path('/');
};
});