关闭

angularJSONP简洁版

102人阅读 评论(0) 收藏 举报
分类:
<!DOCTYPE html>
<html  ng-app="myApp">
<head lang="en">
    <meta charset="UTF-8">
    <title>服务</title>
    <link rel="stylesheet" href="Presently/css/bootstrap.css"/>
</head>
<body>
<script src="jquery.js"></script>
<script src="angular.js"></script>
<div ng-controller='MyController' class='container'>
<input type='search' ng-model='username' class='form-control'/>
<pre ng-show='username'>
{{data}}
</pre>
</div>
<script>
var app = angular.module('myApp',[]);
app.factory('myFactory',['$http',function($http){
var datas = {};
datas.query = function(username,path){
return $http({
method:'JSONP',
url:'https://api.github.com/user/'+username+'/'+path+'?callback=JSON_CALLBACK'
});
}
return datas;
}]);
app.controller('MyController',['$scope','$timeout','myFactory',function($scope,$timeout,myFactory){
var timeout;
$scope.$watch('username',function(newVal){
if(newVal){
if (timeout) $timeout.cancel(timeout);
timeout = $timeout(function(){
myFactory.query(newVal,'events').success(function(data,status){
$scope.data = data.data;})
},1000)
}
})
}]);




</script>
</body>
</html>
0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:6629次
    • 积分:541
    • 等级:
    • 排名:千里之外
    • 原创:49篇
    • 转载:1篇
    • 译文:0篇
    • 评论:3条
    文章分类
    最新评论