Angular中JSON数据的分页

当用户将url输入到输入中时,我从我的服务器下载数据,然后单击“提交”。 接下来,我用HTML显示这些数据:

{{printResult.pg}}

  • {{offer.name}}

printResult.pg是一些页面

我想从1添加分页到printResult.pg ,当用户将页面Angular调用发布到服务器到下一个数据时。 我怎样才能做到这一点?

我的控制器:

 angular.module('PostService', []) .controller('PageCtrl', function ($scope, PostModel) { var srv = this; srv.offers = []; function postUrlToService(url) { $scope.dataLoading = true; $scope.printResult = null; initCreate(); PostModel.postUrl(url).then(function (result) { srv.offers = result.data; $scope.totalItems = srv.offers.pg; $scope.printResult = srv.offers; $scope.dataLoading = false; }); } function initCreate() { srv.newUrl = {url: ''}; } srv.postUrlToService = postUrlToService; }) .constant('ENDPOINT', 'http://localhost:8080/api/send') .service('PostModel', function ($http, ENDPOINT) { var service = this; function getUrl() { return ENDPOINT; } service.postUrl = function (url) { return $http.post(getUrl(), url); }; }); 

编辑:

我这样做,但当我点击下一页后,电话会执行TWICE。 为什么?

    

///

  $scope.$watch("currentPage + numPerPage", function() { if(urlFromForm.url) { console.log("Klikam + " + $scope.currentPage); console.log("Url: " + urlFromForm.url); pageNumber = $scope.currentPage; postUrlToService(urlFromForm); } }); function postUrlToService(url) { $scope.dataLoading = true; $scope.printResult = null; initCreate(); PostModel.postUrl(url).then(function (result) { srv.offers = result.data; $scope.totalItems = srv.offers.pg; $scope.printResult = srv.offers; $scope.dataLoading = false; }); } function initCreate() { srv.newUrl = {url: ''}; } srv.postUrlToService = postUrlToService; }) .constant('ENDPOINT', 'http://localhost:8080/api/send') .service('PostModel', function ($http, ENDPOINT) { var service = this; function getUrl() { return ENDPOINT; } service.postUrl = function (url) { return $http.post(getUrl(), url); }; });