我正在实现某种动态工作流,当我到达某个点时,我必须重新加载状态来呈现HTML,并重新实例化控制器才能继续。
我发现第二次调用$state.reload()不起作用。这是我们想要的行为吗?我能做些什么来强制重新加载?
if(advanceComplexAction()) {
console.log(self.$state); //This is always been printed in console
self.$state.reload();
}
else {
closeActionWizard();
}我正在检查我的控制台,console.log总是打印出来的,但是我的语句self.$state.reload()只有在我第一次调用它时才能正确运行。
编辑:
我注意到当我第一次重新加载时,我的URL发生了变化,并且变成了父url。这一定是问题所在,因为第三次它只重新加载parentState。我不知道怎么解决这个问题
第一次正常工作时,我的url是:
http://localhost:1234/app/parentstate/childstate在使用reload并且一切正常后,它将移动到父状态。
http://localhost:1234/app/parentstate因此,当我再次重新加载时,它只会重新加载父视图。我将我的路线定义如下。
.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';
}
})
)谢谢
发布于 2016-08-10 15:30:41
我解决了!问题出在我的modalState实现上。我有一个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
}
});改变这个解决了我的问题。感谢您的回复
发布于 2016-08-09 22:01:39
也许你应该试试像这样的
$state.transitionTo('current_state', null, {'reload':true});发布于 2016-08-09 23:28:14
我明白了!
$state.reload(); 是的别名
$state.transitionTo($state.current, $stateParams, { reload: true, inherit: false, notify: true }); "reload:true“刷新父状态!所以你需要避免使用"$state.reload“
试一试
window.location.reload(true)https://stackoverflow.com/questions/38851206
复制相似问题