简体   繁体   English

仅为$ state.go重新加载特定的控制器

[英]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, 因此,从状态client.forms.instance我进入另一个$ state,如下所示,

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

This client.forms.instance.rendering is like this, 这个client.forms.instance.rendering就是这样,

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 . 所以当我$stage.goclient.forms.instance.rendering我想重新加载控制器RenderingController

The URL change correctly. URL正确更改。 But RenderingController is not re initialize everytime. 但是RenderingController并不是每次都重新初始化。

Btw I add that RenderingController with the html to the main view as below. 顺便说一句,我将带有html的RenderingController添加到主视图中,如下所示。

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

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 ): 我认为,您无需在ng-include中手动注入模板,而是需要在父模板( 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. 那么在'client.forms.instance.rendering' ui-router应该知道renderinginstance子级,并且将在url匹配或其state被调用时将适当的模板注入内部并渲染其相关的控制器。

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 https://github.com/angular-ui/ui-router/wiki/Multiple-Named-Views

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM