Join the Stack Overflow Community
Stack Overflow is a community of 6.8 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

I am experiencing an issue with the Angular UI-Router Framework. I have 2 nested views in another one and each time, I change to that "multi-view" View, both controllers I set to the sub-views are reloading there initial methods for both. So when I reload the page and both views are updated, they are both something like double-updated. This leads to the fact, that one of the controllers requests via $http twice some data. Each method I define in the controller will execute twice.

Is there any possibilty to prevent the updating for one of the views. My current suggestion is, that each time a new view is loaded, all ui-views are compiled so it compiles twice for 2 views. :/

The Main HTML:

....
<div ui-view></div>
....

My sub-view is something like this:

...
<div ui-view="view1"></div>
<div ui-view="view2"></div>
...

My App state configuration:

....
.state('model', {
url:"/model/{modelId}",
controller: 'modelCtrl',
templateUrl: 'partials/model.html'
})
.state('model.Overall', {
views: {
  'view1': {
    templateUrl: 'partials/view1/view.html',
    controller: 'view1Ctrl'
  },
  'view2': {
    templateUrl: 'partials/views2/view.html',
    controller: 'view2Ctrl'
  }
}
})
...
share

I'm not sure exactly what each view is for but, if you need to have them both visible at the same time, you could try having the modelCtrl firing the method/function you need to happen on load instead of the subview controllers.

However, if these subviews are being toggled, you could set 'model' to be an abstract state: abstract: true and have one ui-view <ui-view="chewy"></ui-view> (I always say chewy because it's kind of a chewy center?). So then you would have two substates:

.state('model.view1', {
 views: {
  'chewy': {
     templateUrl: 'partials/view1/view.html',
     controller: 'view1Ctrl'
   }
 }
 })
 .state('view2', {
 views: {
   'chewy': {
     templateUrl: 'partials/views2/view.html',
     controller: 'view2Ctrl'
    }
  }
 }) ...
share
    
Thank you for your Intention, this could work but I would prefer a method or way to keep those sub-controllers. For me its much more structured since those 2 states won't stay alone and I am going to add several different states / controllers there. – Deleadon Jan 19 '16 at 15:06

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.