【发布时间】:2015-07-31 17:05:53
【问题描述】:
我有这段代码可以使用 angular-ui 路由器确认 Angular 导航:
$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 中的值是正确的。
有什么问题?
【问题讨论】:
-
尝试删除第一个
event.preventDefault() -
路线先变化后显示模态。不好。
标签: angularjs angular-ui-router angular-ui