-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
40 lines (37 loc) · 1.5 KB
/
Copy pathmain.js
File metadata and controls
40 lines (37 loc) · 1.5 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
angular.module ('admisionApp', [])
.factory ('mongolabResource', function ($http) {
var objName = "persona";
var apiKey = "94m7FxDlMbXUd6CTqpzwRrk8wCrhJKjc";
var mongoURL = "https://api.mongolab.com/api/1/databases/shell/collections/" + objName;
return {
getList: function () {
return $http.get (mongoURL + "?apiKey=" + apiKey, {});
},
addPersona: function (persona) {
return $http.post (mongoURL + "?apiKey=" + apiKey, persona);
},
removePersona: function (persona) {
return $http.delete (mongoURL + "/" + persona._id.$oid + "?apiKey=" + apiKey, {});
}
}
})
.controller ('mainController', function ($scope, mongolabResource) {
$scope.personas = [];
mongolabResource.getList ().then (function (response) {
$scope.personas = response.data;
});
$scope.agregarPersona = function () {
mongolabResource.addPersona ($scope.persona).then (function (response) {
$scope.personas.push (response.data);
});
};
$scope.remove = function (persona) {
mongolabResource.removePersona (persona).then (function (response) {
var index = $scope.personas.indexOf (persona);
$scope.personas.splice (index, 1);
}, function (response) {
console.log ("Ocurrio un error!! :-(");
});
}
})
;