How to access ons-lazy-repeat refresh() function?



  • Re: ons-lazy-repeat won't realize the changes on the model if the size of the list did not change.

    in this topic IliaSky mentions lazyRepeat._provider.refresh() but I don’t know how to inject that into my controller. At the moment I’m using a very hacky method to change the length of the list temporarily to force a refresh.


  • Onsen UI

    @Carson-H The refresh method is exposed in the delegate object. Tutorial here.



  • Thanks for replying Fran but I still don’t know how to access this function from my controller. I wan’t to call refresh after an image has loaded from a database. How can I call delegate.refresh() from my controller? Calling this.delegate.refresh() gives me not a function error.


  • Onsen UI

    @Carson-H It’s done in the tutorial I posted. Just don’t do it right after you define the delegate object, wait a cycle at least. You can use $timeout for that.



  • Hi Fran. I’m sorry if I’m being daft but I don’t see refresh() anywhere in the JavaScript. It is in the HTML, but I don’t know how to call it from JavaScript



  • @Carson-H For documentation of refresh, it is posted here under Methods Summary: https://onsen.io/v2/docs/angular1/ons-lazy-repeat.html

    And for where it is in the tutorial, it was in this line:

    <ons-toolbar-button ng-click="list.delegate.refresh()">Refresh</ons-toolbar-button>
    

    list.delegate.refresh() can be called anywhere within your JS, just note as @Fran-Diox stated, to wait at least a cycle.

    EDIT: Corrected a type not should have been note as @Fran-Diox is correct.



  • Thanks a lot everyone. I understand now. I didn’t realize that list can accessed anywhere in the controller with the this keyword:

    angular
        .module('myApp')
        .controller('MyController', function () {
      var self = this;
      function someFunction () {
        self.delegate.refresh();
      }
    })
    

    It was more of a confusion with angularjs than onsen. Also thanks for the $timeout tip


Log in to reply