title: Angular $locationChangeStart prevent reload & leave page
body: <p>Hi read a lots of posts about prevent relaod and leave page and I try to implement this solution on my SPA apps (angular 1.6) but it does't work</p>
  
  <pre><code>$scope.$on('$locationChangeStart', function (event, next, current) {
              if (true) {
                  var answer = confirm("Test");
                  if (!answer) {
                      event.preventDefault();
                  }
              }    
          });
  </code></pre>
  
  <p>this part of code is executed when I enter on my page and not when I try to go out. Also I've try to inject $window and add two event but doesn't work</p>
  
  <pre><code>$window.onunload = function(event){
              var answer = confirm("onunload");
              if (!answer) {
                  event.preventDefault();
              }
          }
  
  
          $window.onbeforeunload = function (event) {
              var answer = confirm("onbeforeunload");
              if (!answer) {
                  event.preventDefault();
              }
          }
  </code></pre>