獲取上下文,角度,ui路由器,沒什麼特別的,用3個命名的ui-views構建的根視圖。 所以在index.html
我們
<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: { '[email protected]': {templateUrl: '123.html'} } // I wish to update $stateParams in '[email protected]' view
})
.state('main.c', {
url: '/c',
params: ...
views: { '[email protected]': ..., '[email protected]': ..., '[email protected]': .. }
});
是否有去B態在「中心」和「左」的視圖更新$ stateParams的方式?我可以使用服務來獲得它,但是我需要爲我需要的變量添加一個$watch
,它對我來說看起來有點冒險。
進入c狀態我實際上可以得到我想要的,但視圖被重新加載,並且我希望避免這種行爲,因爲我在'左'視圖中有一個畫布。
這在某種程度上還是引起視圖中的所有組件$初始化,然後立即$破壞,這可能會導致一些嚴重的性能的問題。你可以看到你的組件中是否添加了'console.log()'這個'.onnit()'和'this.onDestroy()'。 –