-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontroller.js
More file actions
46 lines (38 loc) · 1.38 KB
/
Copy pathcontroller.js
File metadata and controls
46 lines (38 loc) · 1.38 KB
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
const app = angular.module('webApp', []);
app.controller('whyLikeController', function($scope, $http) {
// get all reasons
$scope.getAllReasons = function() {
$http.get('/reasons').then((response) => {
$scope.allReasons = response.data;
});
}
// delete a Reason
$scope.removeReason = function(reasonID) {
const route = `/delete/${reasonID}`
$http.delete(route).then((response) => {
for(let i = 0; i < $scope.allReasons.length; i++) { // updates webApp without needing to refresh
if(reasonID === $scope.allReasons[i]._id) {
$scope.allReasons.splice(i,1)
}
}
})
}
// post a Reason
$scope.addReason = function(reasonID) {
const reason = {
'comment': $scope.reasonComment,
'date': new Date()
};
$scope.reasonComment = '';
const route = `/add`;
$http.post(route, reason).then((response) => {
$scope.allReasons.push(response.data);
});
}
$scope.convertDate = function(date) {
date = new Date(date);
const months = ['January', 'Febuary', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
return `${months[date.getMonth()]} ${date.getDate()}, ${date.getFullYear()}`;
}
$scope.getAllReasons();
});