How to refresh resolve?

263 Views Asked by At

Using ui-router, I have a state with a resolve function:

.state('tab.social', {
    url: '/social/',
    views: {
      'menuContent': {
        templateUrl: 'templates/social/tab-social.html',
        controller: 'SocialCtrl',
        resolve: {
          socialAuthResolve: socialAuthResolve
        }
      }
    }
  })

I capture the resolve in the controller as follows:

.controller('SocialCtrl', function($scope, SocialAuth, socialAuthResolve) {
    //
    console.log(socialAuthResolve);

    //
    $scope.logOut = function() {
       SocialAuth.logOut();
       $state.go('tab.social', {}, {reload: true});
    };

    //
    $scope.logIn= function() {
       SocialAuth.logIn();
       $state.go('tab.social', {}, {reload: true});
    };
})

However, when either pressing logOut or logIn, my state is not refreshed. I am using some parameters from the resolve socialAuthResolve and would like this to be updated. In this case, the old parameters are still in there.

Only when I refresh my browser, then the variables and the page are updated accordingly. How can I refresh the page after the logOut and logIn? For instance, force to resolve again?

1

There are 1 best solutions below

0
On

Here is a sample state with config:

.state('app.stateName', {
      url: "/theUrl",
      views: {
        'myViewName': {
          templateUrl: "templates/template.html",
          controller: 'SomeController',
          resolve: {
            pleaseResolve: function() {
              console.log("I am resolved");
            }
          }
        }
      }
    })

In my controller (assuming SomeController as mentioned above), whenever I enter into the state I run this.

var res = ($state.$current.self.views.myViewName.resolve.pleaseReslove)
res.call()

This will call my resolve function every time I come into the view.