Blame view

public/js/controllers/NerdCtrl.js 1.26 KB
894b21fa   Geoffrey PREUD'HOMME   Application MEAN ...
1
  // public/js/controllers/NerdCtrl.js
8ae24f57   Geoffrey PREUD'HOMME   Liste des membres
2
3
  angular.module('NerdCtrl', []).controller('NerdController', function ($scope, $http) {
      $scope.formData = {};
894b21fa   Geoffrey PREUD'HOMME   Application MEAN ...
4
  
8ae24f57   Geoffrey PREUD'HOMME   Liste des membres
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
      // when landing on the page, get all Nerds and show them
      $http.get('/api/nerds')
          .success(function (data) {
              $scope.nerds = data;
              console.log(data);
          })
          .error(function (data) {
              console.log('Error: ' + data);
          });
  
      // when submitting the add form, send the text to the node API
      $scope.createNerd = function () {
          console.log('Adding', $scope.formData);
          $http.post('/api/nerds', $scope.formData)
              .success(function (data) {
                  $scope.formData = {}; // clear the form so our user is ready to enter another
                  $scope.nerds = data;
              })
              .error(function (data) {
                  console.log('Error: ' + data);
              });
      };
  
      // delete a Nerd after checking it
      $scope.deleteNerd = function (id) {
          $http.delete('/api/nerds/' + id)
              .success(function (data) {
                  $scope.nerds = data;
                  console.log(data);
              })
              .error(function (data) {
                  console.log('Error: ' + data);
              });
      };
894b21fa   Geoffrey PREUD'HOMME   Application MEAN ...
39
40
  
  });