Created
September 13, 2014 00:56
-
-
Save bernardobarreto/22bf5c6f158d068eaacb to your computer and use it in GitHub Desktop.
Get followers from GitHub's user using AngularJs
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
| <html> | |
| <head> | |
| <meta http-equiv="content-type" content="text/html; charset=utf-8"> | |
| <title>GitHub Followers</title> | |
| </head> | |
| <body data-ng-app data-ng-controller='followersController'> | |
| Username: | |
| <input data-ng-model='username' placeholder='username'></input> | |
| <a href='#' ng-click='getFollowers()'> Get Followers </a> | |
| <br/> | |
| <div data-ng-show='notFound'> | |
| <h3> Not found </h3> | |
| </div> | |
| <div data-ng-show='loaded'> | |
| <h2> {{ username }} Followers: </h2> | |
| <ul> | |
| <li data-ng-repeat="follower in followers"> {{ follower.login }} </li> | |
| </ul> | |
| </div> | |
| <script src='https://ajax.googleapis.com/ajax/libs/angularjs/1.2.24/angular.min.js'></script> | |
| <script> | |
| function followersController($scope, $http) { | |
| $scope.getFollowers = function() { | |
| $scope.notFound = false; | |
| $scope.loaded = false; | |
| $http.get('https://api.github.com/users/' + $scope.username + '/followers') | |
| .success(function(data) { | |
| $scope.followers = data; | |
| $scope.loaded = true; | |
| }) | |
| .error(function() { | |
| $scope.notFound = true; | |
| }); | |
| } | |
| } | |
| </script> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi