-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgithub.js
More file actions
executable file
·34 lines (29 loc) · 1.16 KB
/
Copy pathgithub.js
File metadata and controls
executable file
·34 lines (29 loc) · 1.16 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
(function() {
var github = function($http) //Service, $http service to get user and repos
{
var getUser = function(username)
{
return $http.get("https://api.github.com/users/" + username)
.then(function(response)
{
return response.data;
});
};
var getRepos = function(user)
{
return $http.get(user.repos_url)
.then(function(response)
{
return response.data;
});
}
return { // Revealing Module design pattern. Return github Service API.
getUser: getUser,
getRepos: getRepos
};
};
var module = angular.module("GithubViewer"); //Reference to GithubViewer module that will allow to register the service
module.factory("github", github); //Register the Service with Angular so other components can use it. With Factory
// you can specify a name of service and something that points to the function that returns the
//object with the API. i.e. Return github with object with methods .getUser and .getRepos.
}());