如何在不重新加载ui视图的情况下更新$ stateParams?角度ui路由器 [英] How can i update $stateParams without reloading the ui-view? angular ui router
问题描述
获取上下文,角度,ui路由器,没什么特别的,由3个名为ui-views构建的根视图.
所以在index.html
中,我们有
Get the context, angular, ui-router, nothing special, a root view built with 3 named ui-views.
so in index.html
we have
<body>
<div ui-view='left'>
<div ui-view='center'>
<div ui-view='right'>
</body>
我的路线看起来像
$stateProvider
.state('main', {
url: '/',
views: {
'left': {templateUrl: 'foo.html'},
'center': {templateUrl: 'bar.html'},
'right': {templateUrl: 'xyz.html'}
}
})
.state('main.b', {
url: '/b',
params: { foo: {value: 'bar'} }
views: { 'right@': {templateUrl: '123.html'} } // I wish to update $stateParams in 'left@' view
})
.state('main.c', {
url: '/c',
params: ...
views: { 'left@': ..., 'center@': ..., 'right@': .. }
});
有没有一种方法可以进入b状态以在中心"和左"视图中更新$ stateParams?我可以使用服务来获取它,但是我需要在所需的变量中添加$watch
,这对我来说似乎有点hacky.
Is there a way in going to b state to update the $stateParams in the 'center' and 'left' view?? I can get it using a service but i need to add a $watch
to the variable I need and it looks a little bit hacky to me.
进入c状态实际上可以得到我想要的东西,但是视图已重新加载,并且我希望避免这种行为,因为我在左"视图中有一个画布.
Going into c state I can actually get what I want, but the view is reloaded, and i wish to avoid this behaviour cause i have a canvas in the 'left' view.
推荐答案
您可以使用以下内容转到特定路线,而无需重新加载视图:
You could use the following to go to a specific route without reloading the views:
$state.go('.', {parm1: 1}, {notify: false});
最后一个对象文字表示可以传递给go
的选项.如果将notify
设置为false
,则实际上将阻止重新初始化控制器.开头的.
是您要使用的绝对状态名称或相对状态路径.
The last object literal represents the options which you can pass along to go
. If you set notify
to false
, this will actually prevent the controllers from being reinitialized. The .
at the beginning is the absolute state name or relative state path you wanna go to.
重要的是notify
.
这篇关于如何在不重新加载ui视图的情况下更新$ stateParams?角度ui路由器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!