Javascript 从Angular.js控制器调用函数
下面是一个简单的Angular.js代码片段:Javascript 从Angular.js控制器调用函数,javascript,angularjs,Javascript,Angularjs,下面是一个简单的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";
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 } });
});
$scope.data = GetProductsForIndex.query({ parameters : Obj }, function () {
console.log($scope.data);
$scope.products = $scope.data;
});
我正在尝试使用
在这里的演示中,他们调用了loadMore()
函数
在本例中,我希望在滚动时执行以下操作:
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 } });
});
$scope.data = GetProductsForIndex.query({ parameters : Obj }, function () {
console.log($scope.data);
$scope.products = $scope.data;
});
并将pageIndex
Obj.pageIndex=1
增加1。我该怎么做?今天是我使用Angular.js的第三天。您需要在控制器中实现类似的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);
})