[英]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.go
到client.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应该知道rendering
是instance
子级,并且将在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.