0

The homepage of my angular app has several links to other pages, each of which requires a different resource (but all have the same controller). The home page controller has a function for choosing the next page, which decides which resource to load, and the other controller does manipulations on the resource (they all look the same, so the controller doesn't care) and sends it to the view.

I'd like to have a system where once the user makes a choice as to where to go from the home page, the resource is loaded for that session unless the user explicitly says to unload it. I have a MyResource service that implements initialize and get functions. The controller for the first page calls initialize(option), and the controller for the second page just should just call get when the page is hit. However, when the home page is hit the second controller is instantiated immediately, calls get, and can't find the resource because the user hasn't yet chosen which to load. How do I make the second controller wait to call get until the partial it belongs to is actually hit?

1 Answer 1

1

I think you're looking for the resolve property of $routeProvider , as explained here: Delaying AngularJS route change until model loaded to prevent flicker

Basically if you use a promise of the loaded resource in the second controller, it won't be instantiated until the request has finished and your data is ready.

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

1 Comment

Wow, what a powerful tool. Thanks for introducing me to it, I'd never have known to look for this.

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.