角UI路由器:停止$ state.go重新加载控制器,但更改网址

问题描述:

我的应用程序使用的标签和这个事业之间切换时 $ state.go 重新初始化这些控制器控制器和范围的变量得到更新,并导致内存泄漏。有没有办法阻止重新初始化控制器,但更改URL状态改变?

My app uses $state.go when switching between tabs and this cause to re-initializes the controllers and scope variable in those controllers get updated and causes memory leaks. Is there a way to stop re-initializing the controllers but change URL on state change?

下面的例子是routes.js在我的应用程序。

Example below is routes.js in my app.

.state('home', 
{
    abstract    : true,            
    url         : '/home',
    templateUrl : 'scripts/home.html'
})
.state('home.summary', 
{
    url        : '/summary?userId', 
    controller : 'SummaryCtrl',                
    views      : 
    {               
        summary: 
        {
            templateUrl: 'scripts/home/summary.html'
        }
    }
})
.state('home.summary.detail', 
{
    url        : '/detail/:id',
    controller : 'DetailCtrl',                 
    views      : 
    {               
        detail: 
        {
            templateUrl: 'scripts/home/detail.html'
        }
    }
})

如何停止重装DetailCtrl但更改URL时,要注明home.summary.detail如果DetailCtrl已经加载了独特的ID ???

How to stop reloading DetailCtrl but change URL when going to state home.summary.detail if the DetailCtrl is already loaded for unique id???

也试过$ q.reject儿童状况的决心,它停止重装控制器,但不改变网址。

Also tried to $q.reject in resolve of child state, it stops reload of controllers but doesn't change url.

也试过reloadOnSearch = false时停止控制器的重装,但不改变网址。

Also tried reloadOnSearch=false it stops reload of controllers but doesn't change url.

您可以使用 $ state.transitionTo 而不是 $ state.go 。 $ state.go 要求 $ state.transitionTo 在国内,而且会自动设置选项 {位置:真的,继承:真实的,相对的:$ $状态电流,通知:真正} 。您可以拨打 $ state.transitionTo 并设置地点:假。例如:

You can use $state.transitionTo instead of $state.go . $state.go calls $state.transitionTo internally but automatically sets options to { location: true, inherit: true, relative: $state.$current, notify: true } . You can call $state.transitionTo and set location: false . For example:

$state.go('.detail', {id: newId}) 

可以通过

 $state.transitionTo ('.detail', {id: newId}, { location: false, inherit: true, relative: $state.$current, notify: true })