1

I am trying to stop a situation where the page loads prior to the data, so you get the view updating whilst page is loading.

In UI-router, you can set a 'resolve' which can run a method and retrieve data prior to loading page, which is working fantastically, but I seem to only be able to do this for one method. Is there a way to run multiple methods in a resolve prior to loading the page?

0

1 Answer 1

2

Actually resolve can receive an object as well. And each property would have to be resolved before the controller, so then the state could be achieved.

Each of the objects in resolve below must be resolved (via deferred.resolve() if they are a promise) before the controller is instantiated. Notice how each resolve object is injected as a parameter into the controller (UI-Router docs for resolve).

For example:

$stateProvider.state('myState', {
    resolve: {
        resolve0: function () { // resolve with plain value
            return 'somedata';
        },
        resolve1: function ($q) { // resolve with promise
            return $q.resolve('somedata');
        },
        resolve2: function ($q) { // reject with promise, it will preven state to finish change
            return $q.reject('some error');
        }
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.