2

In the UI Router sample app there is an example where one resolve object is used in the next resolve. https://github.com/ui-router/sample-app-ng1/blob/master/app/mymessages/mymessages.states.js#L76

resolve: {
    // Fetch the current folder from the Folders service, using the folderId parameter
    folder: (Folders, $stateParams) => Folders.get($stateParams.folderId),

    // The resolved folder object (from the resolve above) is injected into this resolve
    // The list of message for the folder are fetched from the Messages service
    messages: (Messages, folder) => Messages.byFolder(folder)
  }

I have tried the below code in ES5 javascript but I get an error:

"Cannot read property 'propertyName' of undefined"

resolve: {
 viewModel: ['viewModelService', function (viewModelService) {
        return viewModelService.get().then(function (response) {
            return response.data;
        });
    }],
    anotherViewModel: this.viewModel.propertyName
}
3
  • what is this.viewModel? it's evaluated to undefined Commented Oct 20, 2016 at 14:53
  • this.viewModel is meant to be the viewModel object that has been resolved above anotherViewModel Commented Oct 20, 2016 at 14:57
  • see my answer then Commented Oct 20, 2016 at 15:01

1 Answer 1

3

This should work:

resolve: {
    viewModel: ['viewModelService', function (viewModelService) {
            return viewModelService.get().then(function (response) {
                return response.data;
            });
        }
    ],
    anotherViewModel: ['viewModel', function (viewModel) {
            viewModel.propertyName
        }
    ]
}
Sign up to request clarification or add additional context in comments.

2 Comments

Brilliant. Works well.
@WilJones, no problem. You can accept my answer if it helped.

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.