-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainController.js
More file actions
64 lines (43 loc) · 1.74 KB
/
Copy pathMainController.js
File metadata and controls
64 lines (43 loc) · 1.74 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// Code goes here
(function() {
var app = angular.module("githubViewer")
var MainController = function($scope, github, $interval,$location) {
var onUserComplete = function(data) {
//$scope.user = response.data;
// $http.get($scope.user.repos_url).then(onRepos, onError);
$scope.user = data;
github.getRepos($scope.user).then(onRepos);
};
var onRepos = function(data) {
//$scope.repos = response.data;
$scope.repos = data;
}
var onError = function(reason) {
$scope.error = "Can't retrieve data."
};
var decrementCount = function() {
$scope.countdown -= 1;
if ($scope.countdown < 1) {
$scope.search($scope.username);
}
};
var countDownInterval =null;
var startCount = function() {
countDownInterval = $interval(decrementCount, 1000, $scope.countdown);
};
$scope.search = function(username) {
// $http.get("https://api.github.com/users/" + username)
// .then(onUserComplete, onError);
if(countDownInterval){
$interval.cancel(countDownInterval);
$scope.countDown = null;}
$location.path("/user/" + username);
};
$scope.username = "Angular";
$scope.message = "Github Viewer";
$scope.repoSortOrder = "-stargazers_count";
$scope.countdown = 5;
startCount();
};
app.controller("MainController", MainController);
}());