ionic-frameworkpull-to-refreshjsdatajs-data-angular

ionic refresh with jsdata doesnt seem to work


My ionic app uses jsdata datastore for caching http://www.js-data.io/docs/home .
I am trying to implement the pull to refresh feature in my app using ion-refresher directive.

The doRefresh doesnot seem to make a Get Call at all.
When I click on Pull to refresh, all the console.log messages in the code below get executed.
However, if I check the Network's tab, I dont see a Get call being made at all.
No data gets refreshed, nor do I get any error.
I am not sure why this is happening or what I am doing wrong.

My code:

HTML:
<ion-refresher
            pulling-text="Pull to refresh..."
            on-refresh="doRefresh()">
    </ion-refresher>

Controller:

.controller('ProfileInfo', function($scope, Profile) {

  $scope.load = function() {
        $scope.error = undefined;


        Profile.findAll().then(function(response) {
            $scope.Profile = response[0];


          }).catch(function(err) {
            $scope.error = err;
          });
      };

   $scope.load();


$scope.doRefresh = function() {
        console.log("hi")
        $scope.error = undefined;
        $scope.Profile = [];
            Profile.findAll().then(function(response) {
            console.log($scope.Profile)
            $scope.Profile = response[0];
                console.log($scope.Profile)
            console.log("Done")

        }).catch(function(err) {
            console.log("err", err)
            $scope.error = err;
        }).finally(function(){
            console.log("in finally")
             $scope.$broadcast('scroll.refreshComplete');
        });
    };

});

Solution

  • Inside your doRefresh method, you need to pass bypassCache: true to findAll all to force it try make a new request, e.g.

    var query = {};
    var options = {
      bypassCache: true
    };
    Profile.findAll(query, options).then(...);
    

    Read more about the behavior of DS#findAll in JSData 2.x.