我正在尝试调用github api并使用ng repeat绘制数据。但是当数据使用AJAX时,它的值不会更新。 我做错了什么
这是我的html部分。
<div infinite-scroll='totalData.nextPage()' infinite-scroll-disabled='totalData.busy' infinite-scroll-distance='1' >
<div ng-repeat='item in totalData.items' >
<span class='score'>{{item.owner.id}}</span>
</div>
<div ng-show='reddit.busy'>Loading data...</div>
这是我的js部分。
var app = angular.module('ngTableTutorial', ['infinite-scroll']);
app.controller('tableController', function ($scope, $filter,Reddit) {
$scope.totalData = new Reddit();
});
app.factory('Reddit', function($http) {
var Reddit = function() {
this.items = [];
this.busy = false;
this.after = 'https://api.github.com/repositories?since=862'+ "&jsonp=JSON_CALLBACK";
};
Reddit.prototype.nextPage = function() {
if (this.busy) return;
this.busy = true;
var url = this.after+ "&jsonp=JSON_CALLBACK";
$http.get(url).success(function(data, status, headers, config) {
var regExp = /\<([^>]+)\>/;
var test = regExp.exec(headers().link);
console.log(test)
console.log(data,headers().link)
this.items.push(data)
this.after = test[1];
this.busy = false;
}.bind(this));
};
return Reddit;
});