-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainService.js
More file actions
27 lines (25 loc) · 1.04 KB
/
mainService.js
File metadata and controls
27 lines (25 loc) · 1.04 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
myApp.factory('mainService', ['$http', '$q', function mainService($http, $q) {
// interface
var service = {
values: [],
url:"",
getvalues: getvalues
};
return service;
// implementation
function getvalues(url) {
var def = $q.defer();
//ajax call
$http.get(url)
.then(function successCallback(response){
service.values = response.data;
def.resolve(response.data);
},
function errorCallback(response){
console.log('Failed: ', response);
alert('Call failed');
def.reject("Failed to get values");
});
return def.promise;
}
}]);