-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUserController.js
40 lines (28 loc) · 1.03 KB
/
UserController.js
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
// Code encapusuled in a module githubViewer
(function() {
// Just reference to githubViewer module
var app = angular.module("githubViewer");
// My controller
// $routeParams this will give any parameters that are in the url
var UserController = function($scope, github, $routeParams, $location) {
var onUserComplete = function(data) {
$scope.user = data;
github.getRepos($scope.user).then(onRepos, onError);
};
var onRepos = function(data) {
$scope.repos = data;
};
var onError = function(reason) {
$scope.error = "Could not fetch the data";
};
// Add function to scope
$scope.reportInfo = function(username, reponame){
$location.path("/repo/" + username + "/" + reponame);
};
// Lets initialized my variable username in my scope
$scope.username = $routeParams.username;
$scope.repoSortOrder = "-stargazers_count";
github.getUser($scope.username).then(onUserComplete, onError);
};
app.controller("UserController", UserController);
}());