question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Endless loop when assing onPaginate function to the md-on-paginate attribute

See original GitHub issue

Hello to everyone. As the title says I am facing an issue with the md-on-paginate attribute. I am fairly new with angular so I don’t clearly understand what is going wrong.

Here is my code:

(function() {

    'use strict';

    angular.module('representatives.module')
        .controller('representativesController', representativesController);

    /* @ngInject */

    function representativesController($resource) {

        var vm = this;
        vm.onPaginate = onPaginate;        
        vm.getRepresentatives = getRepresentatives;
        vm.checked = false;
        vm.results = [];
        vm.progress = undefined;
        vm.filterVisibility = false;


        vm.filters = {
            search: '',
            limit: '10',
            order: '-id',
            page: 1,
            dateFrom: '',
            dateTo: ''
        };


        var Representatives = $resource('http://localhost/brb.rebates/api/v1/representatives');

        function getRepresentatives(filters) {
            vm.promise = Representatives.get(filters || vm.filters, success).$promise;
        }

        function success(representatives) {
            vm.representatives = representatives;
        }

       function onPaginate(page, limit) {
            getRepresentatives(angular.extend({}, vm.filters, {
                page: page,
                limit: limit
            }));
        }
    }

})();

//=================================================================

<md-table-pagination md-limit="vm.filters.limit" md-page="vm.filters.page" md-total="{{vm.results.Data.Criteria.TotalItems}}"
        md-on-paginate="vm.onPaginate()" md-page-select></md-table-pagination>

And I get multiple errors:

Error: [$rootScope:infdig] 10 $digest() iterations reached. Aborting!
Watchers fired in the last 5 iterations: []
http://errors.angularjs.org/1.4.8/$rootScope/infdig?p0=10&p1=%5B%5D
    at vendor.js:31
    at h.$digest (vendor.js:33)
    at h.$apply (vendor.js:33)
    at HTMLButtonElement.<anonymous> (vendor.js:35)
    at HTMLButtonElement.J.event.dispatch (vendor.js:25)
    at HTMLButtonElement.g.handle (vendor.js:24)

Any suggestions?

Thank you in advance.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

6reactions
daniel-nagycommented, Feb 27, 2016

Remove the parentheses.

md-on-paginate="vm.onPaginate"

Explanation

I’m using two-way data binding for the callback functions,

onPaginate: '=?mdOnPaginate'

So you’re essentially passing the function to the directive. The way you had it, the result of executing your function was passed to the directive, I think.

1reaction
kventcommented, Feb 28, 2016

Thank you very much Daniel! It works!

Read more comments on GitHub >

github_iconTop Results From Across the Web

i get an infinite loop when attempting to paginate data
I am trying to paginate some data. The limit of results per query are 300, and I can use an offset to get...
Read more >
Database: Pagination - The PHP Framework For Web Artisans
The paginate method counts the total number of records matched by the query before retrieving the records from the database. This is done...
Read more >
Pagination with VueJS, Bootstrap and Github API - Medium
Pagination is a commonly used way to display a large set of data. And VueJS makes it easy to create a good UX...
Read more >
Paging Implementation | Writing an OS in Rust
This post shows how to implement paging support in our kernel. It first explores different techniques to make the physical page table frames ......
Read more >
How To Limit and Paginate Query Results in Laravel Eloquent
You'll now update the Eloquent queries in routes/web.php to use the simplePaginate() method, which generates a basic navigation with ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found