Created
September 6, 2015 19:42
-
-
Save rafaell-lycan/a50fb210639afce20810 to your computer and use it in GitHub Desktop.
Simple $http Angular exemple with Browserify and ES6
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
//app.js | |
var angular = require('angular'); | |
angular.module('app', []); | |
require('./services/GithubService'); | |
require('./controllers/MainController'); |
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
//services/GithubService.js | |
function GithubService ($http) { | |
var url = 'https://api.github.com/users/'; | |
var getUser = () => $http.get(url + user); | |
return { | |
getUser : getUser | |
}; | |
} | |
GithubService.$inject = ['$http']; | |
angular.module('app').factory('GithubService', GithubService); |
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
//controllers/MainController.js | |
function MainCtrl (GithubService) { | |
var vm = this; | |
vm.user = ''; | |
GithubService.getUser('rafaell-lycan').then( | |
data => vm.user = data, | |
error => console.log(error) | |
); | |
} | |
GithubService.$inject = ['GithubService']; | |
angular.module('app').controller('MainCtrl', MainCtrl); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment