DilumN
DilumN

Reputation: 2895

Reload only particular controller for $state.go

I have a nested routing in my single page application. So from state client.forms.instance I go to another $state as below,

 $state.go('client.forms.instance.rendering', { 'sectionId': sectionId });

This client.forms.instance.rendering is like this,

var forms = {
            url: '/sections/:sectionId',
            templateUrl: 'scripts/client/forms/formInstance/rendering/formRendering.html',
            controller: 'RenderingController',
            controllerAs: 'vm',
        };
        $stateProvider.state('client.forms.instance.rendering', forms);

So when I $stage.go to client.forms.instance.rendering I want to reload controller RenderingController.

The URL change correctly. But RenderingController is not re initialize everytime.

Btw I add that RenderingController with the html to the main view as below.

<div ng-include="'scripts/client/forms/formInstance/rendering/formRendering.html'"></div>

Upvotes: 1

Views: 283

Answers (1)

Salem Ouerdani
Salem Ouerdani

Reputation: 7886

try this :

$state.go('client.forms.instance.rendering',{'sectionId':sectionId},{reload:true});

To not reload the parent controller. I think instead of manually injecting the template within ng-include, you'll need to add this inside parent template (instance):

<div ui-view></div>

then within 'client.forms.instance.rendering' ui-router should know that rendering is child of instance and will inject the appropriate template inside and render its related controller whenever the url is matching or its state is invoked.

In case if many states should be injected in the same page. then you may consider using named views. More details can be found here :

https://github.com/angular-ui/ui-router/wiki/Multiple-Named-Views

Upvotes: 1

Related Questions