[英]$state.reload() moves to parent's $state
I'm implementing some kind of dynamic workflow and when I reach a certain point I must reload my state to render the HTML and reinstantiate the controller in order to continue. 我正在实现某种动态工作流程,当我达到某一点时,我必须重新加载我的状态以呈现HTML并重新实例化控制器以便继续。
What I've found is that the second time that I call $state.reload()
is not working. 我发现第二次调用$state.reload()
是行不通的。 Is this the desired behavior? 这是理想的行为吗? What can I do to force this reload? 我该怎么做才能强制重新加载?
if(advanceComplexAction()) {
console.log(self.$state); //This is always been printed in console
self.$state.reload();
}
else {
closeActionWizard();
}
I'm checking my console and the console.log is always printed but my statement self.$state.reload()
only runs correctly the first time that I call it. 我正在检查我的控制台和console.log总是打印但我的语句是self.$state.reload()
只在我第一次调用它时才能正确运行。
EDIT: 编辑:
I noticed that my url change when I do the first reload and is changing to the parent URL. 我注意到,当我第一次重新加载并更改为父URL时,我的URL会更改。 That must be the problem because the third time it only reload the parentState. 这一定是问题,因为它第三次只重新加载parentState。 I don't know how to solve this 我不知道如何解决这个问题
First time that is working correctly my url is: 第一次正常工作我的网址是:
http://localhost:1234/app/parentstate/childstate
After using reload and everything worked it moves to the parent state. 使用重新加载后,一切正常,它将移动到父状态。
http://localhost:1234/app/parentstate
So when I do reload again it only reloads the parent view. 因此,当我再次重新加载时,它只重新加载父视图。 I'm defining my routes as follow. 我正在定义我的路线如下。
.config(function($stateProvider, modalStateProvider){
$stateProvider
.state('app.parentstate',
modalStateProvider.create({
animation: true,
name: 'app.parentsate',
url: 'apps/parentstate',
controllerAs: 'parentCtrl',
controller: 'ParentCtrl',
windowClass: 'semi-modal semi-modal--XXL',
templateUrl: function() {
return 'app/ui/apps/parent/parent.html';
},
resolve: {
//Some resolve function
}]
}
})
)
.state('app.parentstate.childstate',
modalStateProvider.create({
animation: true,
name: 'app.parentstate.childstate',
url: '/childstate',
controllerAs: 'childWizardCtrl',
controller: 'ChildWizardCtrl',
windowClass: 'semi-modal semi-modal--XL',
templateUrl: function(){
return 'app/ui/apps/child/child.html';
}
})
)
Thank you 谢谢
也许你会尝试类似的东西
$state.transitionTo('current_state', null, {'reload':true});
I get it ! 我知道了 !
$state.reload();
is an alias for 是别名
$state.transitionTo($state.current, $stateParams, { reload: true, inherit: false, notify: true });
"reload:true" refresh the parent state ! “reload:true”刷新父状态! so you need to avoid using "$state.reload" 所以你需要避免使用“$ state.reload”
Try instead 试试吧
window.location.reload(true)
I Solved it! 我解决了! The problem was with my implementation of modalState. 问题出在我的modalState实现上。 I have an OnEnter function that moves to my parent state automatically if my state is the same or if I close it. 我有一个OnEnter函数,如果我的状态相同或者我关闭它,它会自动移动到我的父状态。
modalInstance.result
.then(function(result) {
$log.debug('Modal result', result);
}, function(rejection) {
$log.debug('Modal dismissed at: ' + new Date() + ' because ' + rejection);
})
.finally(function() {
modalInstance = null;
if ($state.$current.name === options.name) {
$state.go('^', $stateParams, { reload: options.reload }); //Here we are moving to parent state
}
});
Changing this fixed my problem. 改变这个解决了我的问题。 Thanks for your responses 谢谢你的回复
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.