[英]Calling a function from Angular.js Controller
Following is a simple Angular.js code snippet : 以下是一个简单的Angular.js代码段:
XApp.controller('ProductsController', function ($scope, GetProductsForIndex, $http) {
console.log('Step 1');
var Obj = new Object();
Obj.PAGEINDEX = 1;
Obj.PAGESIZE = 25;
Obj.SPNAME = "index_get_products";
Obj.PAGECOUNT = null;
Obj.COUNTRYCODE = 'in'
$scope.data = GetProductsForIndex.query({ parameters : Obj }, function () {
console.log($scope.data);
$scope.products = $scope.data;
});
})
XApp.factory('GetProductsForIndex', function ($resource) {
console.log('Step 2');
return $resource('api/index/:object?type=json', {}, { 'query': { method: 'GET', isArray: true } });
});
I am trying to implement infinite scroll using http://binarymuse.github.io/ngInfiniteScroll/ 我正在尝试使用http://binarymuse.github.io/ngInfiniteScroll/实现无限滚动
In their demo here http://binarymuse.github.io/ngInfiniteScroll/demo_basic.html they are calling the loadMore()
function. 在这里的http://binarymuse.github.io/ngInfiniteScroll/demo_basic.html演示中,他们正在调用loadMore()
函数。
In my case i want to execute the following on scroll : 就我而言,我想在滚动上执行以下命令:
$scope.data = GetProductsForIndex.query({ parameters : Obj }, function () {
console.log($scope.data);
$scope.products = $scope.data;
});
and increment the pageIndex Obj.PAGEINDEX = 1
by 1. How am i supposed to do that? 并将pageIndex Obj.PAGEINDEX = 1
递增1。我应该怎么做? Today is my 3rd day with Angular.js. 今天是我与Angular.js合作的第三天。
You need to implement a loadMore function like this inside your controller , 您需要在控制器内部实现这样的loadMore函数,
XApp.controller('ProductsController', function ($scope, GetProductsForIndex, $http) {
function loadData($scope, obj){
$scope.products.push( GetProductsForIndex.query({ parameters : Obj }, function () {
}));
}
console.log('Step 1');
var Obj = new Object();
$scope.products=[];
Obj.PAGEINDEX = 1;
Obj.PAGESIZE = 25;
Obj.SPNAME = "index_get_products";
Obj.PAGECOUNT = null;
Obj.COUNTRYCODE = 'in'
loadData($scope, Obj);
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.