首页 > 代码库 > Angular service
Angular service
<!DOCTYPE html><html lang="en" ng-app="myApp"><head> <meta charset="UTF-8"> <title>Document</title> <script src="lib/angular.js"></script></head><body> <div ng-controller="ServiceCtrl"> <label for="username"> Type in a Github username </label> <input type="text" ng-model="username" placeholder="Enter a Github username"> <ul> <li ng-repeat="event in events"> {{event.actor.login}} {{event.repo.name}} </li> </ul> </div> <script> angular.module(‘myApp.services‘, []) .factory(‘githubService‘, function ($http) { var githubUrl = ‘https://api.github.com‘; var runUserRequest = function (username, path) { return $http({ method: ‘JSONP‘, url: githubUrl + ‘/users/‘ + username + ‘/‘ + path + ‘?callback=JSON_CALLBACK‘ }); } return { events: function (username) { return runUserRequest(username, ‘events‘); } } }); angular.module(‘myApp‘, [‘myApp.services‘]) .controller(‘ServiceCtrl‘, function ($scope, githubService) { $scope.$watch(‘username‘, function (newUsername) { githubService.events(newUsername).success(function (data, status, headers) { $scope.events = data.data; }) }); }); </script></body></html>
Angular service
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。