6

I have multiple nested views ui-view on my page with corresponding states to set templates in those views. When I transition to a child state, controller associated to each of its parent states gets called. I want to prevent this. For example, if I transition to state root.question.mcq.menu, the controller associated with state root.question.mcq too gets called.

How can I prevent this so that only the controller associated with root.question.mcq.menu gets called.

1
  • What does your code look like? Commented Jul 3, 2015 at 12:32

1 Answer 1

1

It depends where you come from. Do you come from the parent or from a sibling of the target state the parent controller should not be initialized. But if you come from any other state the parent controller will be initialized. If this behavior is wrong for you then you probably have a design issue.

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

6 Comments

This is absolutely correct, and just to reinforce the point, instantiating the parent's controller when transitioning to the child is fundamental to the design of UI Router. The state hierarchy maps to the DOM hierarchy, so it doesn't make sense to think about instantiating a child without its parent.
I come from parent and as it is already initialized, I think its controller should not be initialized again.
Please provide a plunker?
@Michael it is not possible for me to provide a plunker. But I want to know what's the expected behaviour here. Does parent controller normally called if we transition from parent to child state? If not , are there any special cases when it could happen.
@Michael Please can you help me out here?
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.