Angularjs 禁用返回、重新加载/刷新、更改位置/url

Angularjs 禁用返回、重新加载/刷新、更改位置/url,angularjs,Angularjs,如果我的表单仍然无效,或者在上载文件时,如何禁用更改$location或重新加载$location windowElement.on('beforeunload', function(event) { if(form === false) { event.preventDefault(); } }); 我也试过了 $scope.$on('$locationChangeStart', function(event) { if(form === false) { event.p

如果我的表单仍然无效,或者在上载文件时,如何禁用更改$location或重新加载$location

windowElement.on('beforeunload', function(event) {
  if(form === false) {
  event.preventDefault();
  }
});
我也试过了

$scope.$on('$locationChangeStart', function(event) {
  if(form === false) {
  event.preventDefault();
  }
});

他们都不工作

$scope.$on('$locationChangeSuccess', function(event) {
  if(form === false) {
  event.preventDefault();
  }
});