Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Re" resolve resources with angular ui router without reload

I am using the following code to resolve a resource when the main state is loaded. Is it possible to re - resolve the resource without reloading the page? I am avoiding reload so that the user experience is not affected.

    $stateProvider
        .state('main', {
            url: '/',
            templateUrl: 'publicApp/main.html',
            controller: 'MainCtrl as mainCtrl',
            resolve: {
                userData: ["UserApi", function (UserApi) {
                    return UserApi.getUserData().$promise;
                }]
            }
        })


    .controller('MainCtrl', function (userData) {
        console.log(userData.something);
    })

Since is a public site, the user can visit any page without logging in but when the user logs in the page must customize based on the user data.

EDIT

I am using a modal for login so the state doesn't reload after logging in, I was thinking of throwing an event on $rootScope and then add listeners in controllers to load them again. But this doesn't look good, so I am looking for a better way

I currently have two options:

  1. Reload page - will effect the user experience, so its the last option
  2. Throw an event for the login modal and catch it in other controllers

Any better ideas?

like image 734
Nikhil Bhandari Avatar asked Dec 17 '14 08:12

Nikhil Bhandari


1 Answers

Try using state reload once promise is resolved

$state.reload();

like image 89
Aqib Mapari Avatar answered Oct 26 '22 18:10

Aqib Mapari