Skip to content

Instantly share code, notes, and snippets.

@tedhagos
Created November 23, 2017 01:48
Show Gist options
  • Select an option

  • Save tedhagos/a834e8ea9c19102ecbc2066c4f4ccca2 to your computer and use it in GitHub Desktop.

Select an option

Save tedhagos/a834e8ea9c19102ecbc2066c4f4ccca2 to your computer and use it in GitHub Desktop.
ngService
const myservice = ($http) => {
let github = () => {
return $http.get('https://api.github.com/users/angular')
.then((data) => {
return data.data;
})
}
return {
xgithub: github
}
}
app = angular.module('app');
app.factory('ms', myservice);
<html ng-app="app">
<body ng-controller="ctrl">
{{user.login}}
<img ng-src="{{user.avatar_url}}" alt="">
<script src="libs/angular/angular.js"></script>
<script>
let app = angular.module('app', []);
app.controller('ctrl', ($scope, ms) => {
myservice.xgithub().then(function(data){
console.log(data);
$scope.user = data;
});
});
</script>
<script src="8-service.js"></script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment