Created
June 13, 2016 14:39
-
-
Save ozluy/0bf978889bfca2a1e593f9abdf787bec to your computer and use it in GitHub Desktop.
Angular Simple Factory
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" type="text/css" /> | |
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.0/angular.min.js"></script> | |
</head> | |
<body> | |
<div class="container" ng-app='repos'> | |
<div class="row"> | |
<div class="col-md-12" ng-controller="TabController as tab"> | |
<ul class="nav nav-tabs"> | |
<li role="presentation" ng-class="{active:tab.isSet(1)}"><a ng-click="tab.setTab(1)" href="#">Repositories</a> | |
</li> | |
<li role="presentation" ng-class="{active:tab.isSet(2)}"><a ng-click="tab.setTab(2)" href="#">Contributior</a> | |
</li> | |
</ul> | |
<ul ng-show="tab.isSet(1)" class="list-group" ng-controller="ReposController as reposCtrl"> | |
<li class="list-group-item" ng-repeat="repo in reposCtrl.repos | orderBy: '-forks_count' "> | |
{{repo.name}}, {{repo.language}} <span class="badge">{{repo.forks_count}}</span></li> | |
</ul> | |
<ul ng-show="tab.isSet(2)" class="list-group" ng-controller="ContributorsController as contribCtrl"> | |
<li class="list-group-item" ng-repeat="contrib in contribCtrl.contribs | orderBy: '-contributions' "> | |
{{contrib.nickname}}, {{contrib.team}} <span class="badge">{{contrib.contributions}}</span></li> | |
</ul> | |
</div> | |
</div> | |
</div> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function() { | |
var app = angular.module('repos', []); | |
app.controller('ReposController', function(Repos) { | |
var ctrl = this; | |
this.repos = []; | |
Repos.all().success(function(data) { | |
ctrl.repos = data; | |
}); | |
}); | |
app.controller('ContributorsController', function(Contributors) { | |
var ctrl = this; | |
this.contribs = []; | |
Contributors.all().success(function(data) { | |
ctrl.contribs = data; | |
}); | |
}); | |
app.controller('TabController', function() { | |
var ctrl = this; | |
ctrl.tab = 1; | |
ctrl.setTab = function(tabId) { | |
ctrl.tab = tabId; | |
}; | |
ctrl.isSet = function(tabId) { | |
return ctrl.tab === tabId; | |
}; | |
}); | |
app.factory('Contributors', ['$http',function ContributorsFactory($http) { | |
return{ | |
all: function(){ | |
return $http({method:"GET", url:"https://ozluy.github.io/projects/x-formation/data/contributors.json"}); | |
} | |
}; | |
}]); | |
app.factory('Repos', ['$http',function ReposFactory($http) { | |
return{ | |
all: function(){ | |
return $http({method:"GET", url:"https://api.github.com/users/x-formation/repos"}); | |
} | |
}; | |
}]); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment