title: AngularJS: get filtered ng-repeat result count to update my pagination
body: <p><strong>My code explained:</strong></p>
  
  <p>Below is a simple table with an <code>ng-repeat</code> that loops through <code>ctrl.persons</code>, and stores the results in the variable <code>ctrl.results</code>. There is a filter included that allows a user to search the results using a text input, and <code>sliceResults</code> is a custom filter for my <a href="http://angular-ui.github.io/bootstrap/#/pagination" rel="nofollow">Angular-UI pagination</a> (it determines the offset and limit of results to display based on the current page of the pagination).</p>
  
  <pre><code>&lt;table&gt;
      &lt;tr ng-repeat="result in ctrl.results = (ctrl.persons | filter:searchKeywords) | sliceResults: ctrl.paginationOffset : ctrl.paginationLimit"&gt;
          &lt;td&gt;{{ $index+1 }}&lt;/td&gt;
          &lt;td&gt;{{ result.firstName }}&lt;/td&gt;
          &lt;td&gt;{{ result.lastName }}&lt;/td&gt;
      &lt;/tr&gt;
  &lt;/table&gt;
  
  Results : {{ ctrl.results.length }}
  </code></pre>
  
  <p><strong>Situation:</strong></p>
  
  <p>At the end of the code, <code>ctrl.results.length</code> returns the amount of results real-time, and changes accordingly when a user fills out the text input to search through the results.</p>
  
  <p>However, when the amount of results change, my pagination does not change accordingly and therefore shows an incorrect amount of pages (e.g. it can still show 3 pages while there is only 1 page). The amount of pages is based on a variable in my controller (<code>this.paginationTotalItems</code>).</p>
  
  <p><strong>Question:</strong></p>
  
  <p>How do I update the variable <code>this.paginationTotalItems</code> in my controller as soon as the amount of results (<code>ctrl.results.length</code>) change in my view? (Or, what alternative way is there to update my pagination?)</p>
  
  <p><strong>What I tried:</strong></p>
  
  <p>I am far from being an AngularJS expert, so don't laugh at me! I tried to put a function in <code>ng-change</code> with the result count, which failed because apparently it requires <code>ng-model</code> and I don't see that working with <code>ng-repeat</code>.</p>
  
  <p>I also tried to use <code>$watch</code> on the <code>ctrl.results</code> variable, but that results in a massive console error because it aborts after x iterations. Also, I'd rather not use <code>$watch</code> because I read it only works with <code>$scope</code>, which I'd rather not use (I use the "controller as" syntax).</p>
  
  <p>Thanks in advance, I'll accept the answer that helps me solve my issue.</p>