1
我在角度js中非常新。我想要做的是将一个整数参数传递给我的控制器中的http get请求。这就是我的示例代码的样子。无法将参数传递给角度js中的http get请求
(function() {
angular
.module('myApp.directory', [])
.factory('NewsService', function($http)
{
return {
getallnews: function() {
return $http.get('get_all_news_feed.php?page='+pageNumber);
}
};
})
.factory('NewsFeed', function(directoryService) {
var NewsFeed = function() {
this.items = [];
this.busy = false;
this.pageNumber = 1;
};
NewsFeed.prototype.nextPage = function() {
if (this.busy) return;
this.busy = true;
NewsService.getallnews().success(function(data) {
var itemData = data;
for (var i = 0; i < itemData.length; i++) {
this.items.push(itemData[i]);
}
this.pageNumber++;
this.busy = false;
}.bind(this));
};
return NewsFeed;
})
.controller('MyController', function(NewsFeed, NewsService) {
var inst = this;
inst.news = new NewsFeed();
});
})();
我正在构建一个新闻提要应用程序。新闻取自get_all_news_feed.php
页面,我想将参数pageNumber
传递给它。这是在角度实现infinte滚动的同时。
我得到未定义的错误。有任何想法吗?