10

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?

1
  • If the user is not logged in, the userData promise should not be resolved. Probably better calling the getUserData() from controllers that can be used in both logged out and in. Then when the user logs in, resolve this promise and the controller can update it's data. Commented Dec 17, 2014 at 8:51

1 Answer 1

3

Try using state reload once promise is resolved

$state.reload();

Sign up to request clarification or add additional context in comments.

2 Comments

The OP specifically asked for a NO reload option.
He said without reloading the page. $state.reload() does not reload the page. It reloads the state.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.