-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathcore.js
41 lines (37 loc) · 1011 Bytes
/
core.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
// public/core.js
var scotchSpot = angular.module('scotchSpot', []);
function mainController($scope, $http) {
$scope.formData = {};
// when landing on the page, get all Spot and show them
$http.get('/api/spots')
.success(function(data) {
$scope.spots = data;
console.log(data);
})
.error(function(data) {
console.log('Error: ' + data);
});
// when submitting the add form, send the text to the node API
$scope.updateCarNum = function() {
$http.post('/api/spots', $scope.formData)
.success(function(data) {
$scope.formData = {}; // clear the form so our user is ready to enter another
$scope.spots = data;
console.log(data);
})
.error(function(data) {
console.log('Error: ' + data);
});
};
// delete a spot after checking it
$scope.deleteSpot = function(id) {
$http.delete('/api/spots/' + id)
.success(function(data) {
$scope.spots = data;
console.log(data);
})
.error(function(data) {
console.log('Error: ' + data);
});
};
}