title: AngularJS, window.onbeforeunload analogue
body: <p>what analogue in angular for window.onbeforeunload
  i have modal-dialog and i need to call it before un load.</p>
  
  <pre><code>$scope.toggleModal = function (modalChoice) {
              switch (modalChoice) {
                  case 'error':
                      $scope.modalErrorShown = !$scope.modalErrorShown;
                      break;
                  case 'end':
                      $scope.modalEndShown = !$scope.modalEndShown;
                      break;
              }
          }
  </code></pre>
  
  <p>i dont need to check for changing path or url. I need to call every time when i want to close page, change url, refreshening, etc. </p>
  
  <p>Thanks for your attention.</p>