How can I refresh lazy repeat in Angular 1?



  • I am using a lazy repeat in MEAN.JS. I can successfully do a manual refresh of the lazy repeat if I make a button that on ng-click does “mylazyrepeatdelegate”.refresh(). Another way I can successfully refresh the lazy repeat is by calling an Angular function from my Jade file that changes the scope variable which the lazy repeat uses to determine it’s length. Doing this resizes the list which is what I desire. However, when I try to call refresh() in my Angular code, the lazy repeat does not update. I receive the error that refresh is not a function.

    Looking at my code below, am I doing something incorrectly? Is there a way to call the refresh function in Angular, or can it only be done in ng-click? After scouring the documentation and tutorials, I can only find examples of refresh() in Angular for ng-click.

    The code below does not refresh the lazy repeat and gives me the error that refresh() is not a function. I am calling refresh() after filtering the scope variable (array) that the lazy repeat’s length is dependent on.

    The lazy repeat is currently holding a few items, but due to the nature of my app it could potentially hold thousands of items. I do not want them all to load at the same time which is why I’m using lazy repeat.

    I have defined a lazy repeat as follows (Jade and Angular)…

    Jade:
    0_1473100976090_upload-0d158d86-db10-488c-8ca5-8a1e2800f05d

    Angular Delegate:
    0_1473101948267_upload-73f46974-1782-4dbb-91e9-133d205cd581

    Angular Code to refresh Lazy Repeat:
    0_1473101640155_upload-77fe1306-94bb-42d5-9bb0-8c7a839a2462

    I suppose it’s worth mentioning that the delegate is directly below the function in the same controller.

    Error message in the terminal:
    0_1473104059442_upload-cbf5a41f-8a31-4025-a562-7099b2e22742

    I have found this on GitHub but am unclear on what argelius is saying:
    0_1473104311034_upload-6a5709b6-feae-4740-879e-8a1705a65f21


  • Onsen UI

    @rgins16 I cannot see any problem, looks like you understood how to use it. The only possible issue I can think about is that your SearchService.findEventByFilters is completely synchronous and you are creating the delegate object and calling that service in the same cycle. If that’s the case, it would be possible that the delegate object didn’t expose the refresh method yet. Can you try wrapping your service call (or at least the delegate.refresh()) inside a $timeout(..., 0)?



  • Doing as you suggested, I am still receiving the same error. Could this be a bug?

    $timeout(function () {
    … the service…
    }, 0);



  • @Fran-Diox I am using version:

    onsenui@2.0.0-rc.15

    I will try updating the version.



  • After updating to:

    onsenui-2.0.0-rc.17

    I am still facing the same issue.



  • Last update:

    0_1473169640499_upload-195bb25f-f131-46f0-be44-74bab0fbfffc

    The above function correctly refreshes the delegate when I call it using ng-click in a button in my Jade file, but not when I call the function in the service.



  • I solved the issue.

    I don’t like how I solved it, but in the .then of the service, I set the response.data (which contains the new array for the delegate) as a rootscope variable. The lazy repeat updates without the need for me to call refresh().


Log in to reply