在角度确认后$ state.go不会改变航线 [英] $state.go won't change route in angular after confirmation
本文介绍了在角度确认后$ state.go不会改变航线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这样的code确认导航之外的角度,采用了棱角分明的UI路由器:
I have this code to confirm navigation away in angular, using angular-ui router:
$rootScope.$on('$stateChangeStart', function(event, toState, toParams, fromState, fromParams) {
//checks if campaign has been modified without save.
//if yes state change needs to be confirmed by modal
//otherwise simple navigates away
event.preventDefault();
// var _this = this;
_this.toState = toState;
_this.toParams = toParams;
var modalInstance = bootstrapModals.confirm({
title: "Exit without saving?",
message: "You have changes to the campaign. Leave without saving?"
});
modalInstance.then(function(result) {
$state.go(_this.toState.name, _this.toParams);
}, function(error) {
event.preventDefault();
});
});
不过$ state.go只有再次显示模式,没有任何路由变化。在_this.toState.name和_this.toParams值是正确的。
However $state.go only displays the modal again, without any route change. The values in _this.toState.name and _this.toParams are correct.
什么是问题?
推荐答案
您已经成功无限循环。你做一个状态改变时,都回去了code引起的模态再次显示。你需要的答案模式从弹出备份保存到prevent。
You have an infinite loop on success. Every time you do a state change, you go back in the code causing the modal to be displayed again. You need to save the answer to prevent the modal from popping back up.
这篇关于在角度确认后$ state.go不会改变航线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文