MembreCtrl.js
1.53 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
angular.module('MembreCtrl', []).controller('MembreController', ['$scope', '$http', 'SessionService',
function ($scope, $http, SessionService) {
$scope.formData = {};
$scope.canAdd = SessionService.logged
$scope.canDel = SessionService.logged
// when landing on the page, get all Membres and show them
$http.get('/api/membres')
.success(function (data) {
$scope.membres = data;
console.log(data);
})
.error(function (data) {
console.log('Error: ' + data);
});
// when submitting the add form, send the text to the node API
$scope.createMembre = function () {
console.log('Adding', $scope.formData);
$http.post('/api/membres', $scope.formData)
.success(function (data) {
$scope.formData = {}; // clear the form so our user is ready to enter another
$scope.membres = data;
})
.error(function (data) {
console.log('Error: ' + data);
});
};
// delete a Membre after checking it
$scope.deleteMembre = function (id) {
$http.delete('/api/membres/' + id)
.success(function (data) {
$scope.membres = data;
console.log(data);
})
.error(function (data) {
console.log('Error: ' + data);
});
};
}
]);