寻呼

问题描述:

我使用寻呼以下自定义指令和它的伟大工程: https://github.com/michaelbromley/angularUtils/tree/master/src/directives/pagination寻呼

但现在我有50余项,并想使用服务器端分页。我的后端是Azure移动Web服务,但我坚持尝试获取正确的REST调用,以及如何在Angular中使用它以便与我的自定义指令进行分页。

我试图通过我的服务,以充分利用这一如下:

// All Articles 
pfcServices.factory('pfcArticles', ['$resource', function ($resource) { 
return $resource('https://myrestcall.net/tables/articles/:articleID?$top=100&$inlinecount=allpages', { articleID: '@id' }, 
{ 
    'query': { method: "GET", isArray: false }, 
    'update': { method: 'PATCH' } 
} 
); 
}]); 

我的控制器(请注意,我删除了投票功能,以保持这个贴子简洁):

// Articles for Home Paging Test 
pfcControllers.controller('pfcHomeArticlesCtrlTest', ['$scope', 'auth', 'pfcArticles', function ($scope, auth, pfcArticles) { 

$scope.articles = []; 
$scope.totalArticles = 0; 
$scope.articlesPerPage = 50; // this should match however many results your API puts on one page 
getResultsPage(1); 

$scope.pagination = { 
    current: 1 
}; 

$scope.pageChanged = function (newPage) { 
    getResultsPage(newPage); 
}; 

function getResultsPage(pageNumber) { 
    // Using inlinecount creates two objects of "results" and "count" 
    pfcArticles.query(function(data) { 
     $scope.articles = data.results; 
     $scope.totalArticles = data.count; 
    }); 
}  
}]); 

我的HTML (注意,我从控制器中删除了投票功能,使其更加简洁):

<div ng-controller="pfcHomeArticlesCtrlTest"> 
     <table class="table table-striped"> 
      <tr> 
       <th>Votes</th> 
       <th>Title</th> 
       <th>Category ID</th> 
       <th>Link</th> 
      </tr> 

      <tr dir-paginate="article in articles | itemsPerPage:10 total-items=" totalusers"> 

       <td> 
        <div class="col-md-1 voting well"> 
         <div class="votingButton" ng-click="upVote(articlevote);"> 
          <i class="glyphicon glyphicon-chevron-up"></i> 
         </div> 
         <div class="badge badge-inverse"> 
          <div>{{article.articlevotes}}</div> 
         </div> 
         <div class="votingButton" ng-click="downVote(articlevote);"> 
          <i class="glyphicon glyphicon-chevron-down"></i> 
         </div> 
        </div> 
       </td> 
       <td>{{article.articletitle}}</td> 
       <td>{{article.articlecategoryid}}</td> 
       <td><a ng-href="#article/{{article.id}}/{{article.articlelink}}">{{article.articletitle}}</a></td> 
      </tr> 
     </table> 
     <dir-pagination-controls on-page-change="pageChanged(newPageNumber)"></dir-pagination-controls> 
    </div> 

我收到错误如下:

angular.min.js:101 Error: [$parse:syntax] http://errors.angularjs.org/1.3.4/ $parse/syntax? p0=total&p1=is%20an%20unexpected%20token&p2=33&p3=articles%20%7CNaNtemsPerPage%3A10%20total-items%3Dtotalusers&p4=total-items%3Dtotalusers at Error (native)

这似乎是引用“totalusers”但我的控制器有“totalArticles”

自定义指令有使用$服务器端分页的例子HTTP ,但我正在使用ng-resource(上图)。

.controller('UsersController', function($scope, $http) { 
$scope.users = []; 
$scope.totalUsers = 0; 
$scope.usersPerPage = 25; // this should match however many results your API puts on one page 
getResultsPage(1); 

$scope.pagination = { 
current: 1 
}; 

$scope.pageChanged = function(newPage) { 
getResultsPage(newPage); 
}; 

function getResultsPage(pageNumber) { 
// this is just an example, in reality this stuff should be in a service 
$http.get('path/to/api/users?page=' + pageNumber) 
    .then(function(result) { 
     $scope.users = result.data.Items; 
     $scope.totalUsers = result.data.Count 
    }); 
} 
}) 

什么是分页正确的REST URL格式,以及如何使用它我的角度应用程序内?我相信我可以使用$ top,$ skip和$ inlinecount,但我不确定每个自定义指令是如何转换为“页面”的。这是什么导致解析错误?

Ex。 ? https://myrestcall.net/tables/articles $顶部= 100 & $跳过= 50 & $ inlinecount =所有页

+0

在添加更多的记录,看来最大为50每页,但现在我怎么编码这个正确的页面? – Kode 2015-01-26 23:01:46

+1

似乎是文章过滤器上的语法错误:dir-paginate =“article in articles | itemsPerPage:10 total-items =”totalusers“ – 2015-01-30 18:08:53

+0

这正是它的一部分,并对我发布的答案做了一些调整。 – Kode 2015-01-31 04:23:17

这是通过迈克尔·布罗姆利的援助解决的规定在这里:https://github.com/michaelbromley/angularUtils/issues/109