To be or not to be.That is a question!

---源于莎士比亚的《哈姆雷特》

导航

< 2025年4月 >
30 31 1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 1 2 3
4 5 6 7 8 9 10

统计

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>
复制代码

 

posted on   Ijavascript  阅读(298)  评论(0编辑  收藏  举报

编辑推荐:
· 后端思维之高并发处理方案
· 理解Rust引用及其生命周期标识(下)
· 从二进制到误差:逐行拆解C语言浮点运算中的4008175468544之谜
· .NET制作智能桌面机器人:结合BotSharp智能体框架开发语音交互
· 软件产品开发中常见的10个问题及处理方法
阅读排行:
· 后端思维之高并发处理方案
· 千万级大表的优化技巧
· 在 VS Code 中,一键安装 MCP Server!
· 想让你多爱自己一些的开源计时器
· 10年+ .NET Coder 心语 ── 继承的思维:从思维模式到架构设计的深度解析
点击右上角即可分享
微信分享提示