如果任何表单发生更改,我会尝试停止在我的应用程序上导航,并尝试在不保存更改的情况下进行导航。
我想显示一个对话框来显示是否保存导航或放弃或取消导航操作。
我正在使用角度用户界面路由 https://github.com/angular-ui/ui-router
app.config(function($stateProvider, $urlRouterProvider) {
$urlRouterProvider.otherwise('/dashboard');
$stateProvider
.state('dashboard', {
url: '/dashboard',
templateUrl: '/application/private/views/dashboard.html'
})
.state('websites', {
url: '/websites',
templateUrl: '/application/private/views/websites.html'
})
});
我计划进行类似使用 AngularJS 服务单例的实现
app.service('dirtyCheckService', function ($rootScope, dialogService){
});
在控制器级别我可以像这样编写提交点击
app.controller('formSubmitCtrl', function ($scope, dirtyCheckService){
dirtyCheckService.checkForm($scope).then(function(){
//allow navigation
},function(){
//not allowed}
});
我不确定是否已经存在简单的方法
感谢您