LOADING...

Preview

Pen ID
Unlock Campus Themeforest adv

 

Code

   

Get GitHub profile

This field can't be blank

{{mc.error}}

user_avatar

{{mc.user.name}}

{{mc.user.login}}

{{mc.user.location}}

{{mc.user.bio}}

Go to GitHub Profile
JS
function MainController(User) {
  var vm = this;
  vm.user = null;
  vm.findUser = findUser;
  vm.username = 'irvandoval';
  
  vm.welcome = 'Hello World!'

 
  function findUser(form) {
    vm.error = null;
    vm.submitted = true;
    if (form.$valid) {
      //callback
      User.find(vm.username, function(err, user) {
        if (err) {
          console.log(err.data);
          vm.user = null;
          vm.error = err.data.message;
        }
        if (user) {
          vm.user = user.data;
        }
      });
    }
  }
}

function GitHubProfileFactory($http) {
  var GITHUB_API_URL = 'https://api.github.com/users/';
  return {
    find: find
  }

  function find(username, callback) {
    $http.get(GITHUB_API_URL + username)
      .then(function(user) {
        return callback(null, user);
      })
      .catch(function(err) {
        console.log("error");
        return callback(err, null);
      });
  }
}

angular.module('myapp', [])
  .controller('MainController', MainController)
  .factory('User', GitHubProfileFactory);

Description

Get user profile from Github
Term
Wed, 12/27/2017 - 06:58

Related Codes

Pen ID
Pen ID
Pen ID
Square Adv