Note that there are some explanatory texts on larger screens.

plurals
  1. POPagination on a list using ng-repeat
    text
    copied!<p>I'm trying to add pages to my list. I followed the AngularJS tutorial, the one about smartphones and I'm trying to display only certain number of objects. Here is my html file:</p> <pre><code> &lt;div class='container-fluid'&gt; &lt;div class='row-fluid'&gt; &lt;div class='span2'&gt; Search: &lt;input ng-model='searchBar'&gt; Sort by: &lt;select ng-model='orderProp'&gt; &lt;option value='name'&gt;Alphabetical&lt;/option&gt; &lt;option value='age'&gt;Newest&lt;/option&gt; &lt;/select&gt; You selected the phones to be ordered by: {{orderProp}} &lt;/div&gt; &lt;div class='span10'&gt; &lt;select ng-model='limit'&gt; &lt;option value='5'&gt;Show 5 per page&lt;/option&gt; &lt;option value='10'&gt;Show 10 per page&lt;/option&gt; &lt;option value='15'&gt;Show 15 per page&lt;/option&gt; &lt;option value='20'&gt;Show 20 per page&lt;/option&gt; &lt;/select&gt; &lt;ul class='phones'&gt; &lt;li class='thumbnail' ng-repeat='phone in phones | filter:searchBar | orderBy:orderProp | limitTo:limit'&gt; &lt;a href='#/phones/{{phone.id}}' class='thumb'&gt;&lt;img ng-src='{{phone.imageUrl}}'&gt;&lt;/a&gt; &lt;a href='#/phones/{{phone.id}}'&gt;{{phone.name}}&lt;/a&gt; &lt;p&gt;{{phone.snippet}}&lt;/p&gt; &lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; </code></pre> <p>I've added a select tag with some values in order to limit the number of items that will be displayed. What I want now is to add the pagination to display the next 5, 10, etc.</p> <p>I have a controller that works with this:</p> <pre><code>function PhoneListCtrl($scope, Phone){ $scope.phones = Phone.query(); $scope.orderProp = 'age'; $scope.limit = 5; } </code></pre> <p>And also I have a module in order to retrieve the data from the json files.</p> <pre><code>angular.module('phonecatServices', ['ngResource']). factory('Phone', function($resource){ return $resource('phones/:phoneId.json', {}, { query: {method: 'GET', params:{phoneId:'phones'}, isArray:true} }); }); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload