JSFiddle - React, Tailwind, and code Playground
HTML
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.9/angular.min.js"></script>
<div ng-app="app">
<div ng-controller="MainCtrl">
<div>
<button ng-click="getRandomCommit()">Get</button>
</div>
<div class="content">
<div class="commit-message"><a href="{{ commit.html_url }}">{{ commit.commit.message }}</a>
</div>
</div>
</div>
</div>
CSS
div.content {
height: 10em;
position: relative;
font-size: 30px;
line-height: 30px;
text-align: center;
margin-top: 150px;
}
JavaScript
window.api_url = 'https://api.github.com';
var app = angular.module('app', []);
var randInt = function(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
};
app.controller('MainCtrl', function($scope, $http) {
window.h = $http;
window.s = $scope;
$scope.getCommit = function(repoUrl) {
$http.get(repoUrl + '/commits').then(function(response) {
$scope.commit = response.data[randInt(0, response.data.length - 1)];
});
};
$scope.getRandomCommit = function() {
$http.get(window.api_url + '/repositories?since=' + randInt(0, 9999)).then(function(response) {
$scope.repos = response.data;
var repoUrl = $scope.repos[randInt(0, $scope.repos.length - 1)].url;
$scope.getCommit(repoUrl);
});
};
$scope.getRandomCommit();
});