我之前的问题很糟糕,所以我重写了所有内容。
我正在使用 ui.router
按状态进行导航。
正常情况下,如果加载新状态,模板和 Controller 将会刷新/重新加载。由于我在模板中有几个 ng.repeat 和 ng.if ,这会导致闪烁,因为首先 View 将使用空变量进行渲染,并且在 Controller 获取其数据之后再次它将被再次渲染。
我的想法是,我为每个状态主 Controller 定义一个接口(interface)方法(例如“重新激活”)。我将从导航菜单中调用此方法,并在其中设置状态。 这实际上效果很好。
var controllerScope = angular.element($('#content')).scope();
controllerScope.reactivated();
我的问题是:如何在切换到另一个状态时保持 $state
的状态(渲染的 html、 Controller 状态),并且如果重新输入则从我离开的地方继续?
最佳答案
或者,如果用户单击事件链接,您可以阻止状态更改
$rootScope.$on('$stateChangeStart',
function(event, toState, toParams, fromState, fromParams){
event.preventDefault();
// transitionTo() promise will be rejected with
// a 'transition prevented' error
})
关于javascript - 用户界面.路由器 : Save $state state when leaving and continous when reentering,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38007686/