Created
November 23, 2017 01:48
-
-
Save tedhagos/a834e8ea9c19102ecbc2066c4f4ccca2 to your computer and use it in GitHub Desktop.
ngService
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
| 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); |
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 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