title: AngularJS $location not changing the path
body: <p>I'm having an issue with changing the URL of the page after a form has been submitted.</p>
  
  <p>Here's the flow of my app:</p>
  
  <ol>
  <li>Routes are set, URL is recognized to some form page.</li>
  <li>Page loads, controller sets variables, directives are fired.</li>
  <li>A special form directive is fired which performs a special form submission using AJAX.</li>
  <li>After the AJAX is performed (Angular doesn't take care of the AJAX) then a callback is fired and the directive calls the <code>$scope.onAfterSubmit</code> function which sets the location.</li>
  </ol>
  
  <p>The problem is that after setting the location the nothing happens. I've tried setting the location param to <code>/</code> as well... Nope. I've also tried not submitting the form. Nothing works.</p>
  
  <p>I've tested to see if the code reaches the <code>onAfterSubmit</code> function (which it does).</p>
  
  <p>My only thought is that somehow the scope of the function is changed (since its called from a directive), but then again how can it call <code>onAfterSubmit</code> if the scope changed? </p>
  
  <p>Here's my code</p>
  
  <pre><code>var Ctrl = function($scope, $location, $http) {
    $http.get('/resources/' + $params.id + '/edit.json').success(function(data) {
      $scope.resource = data;
    });
  
    $scope.onAfterSubmit = function() {
      $location.path('/').replace();
    };
  }
  Ctrl.$inject = ['$scope','$location','$http'];
  </code></pre>
  
  <p>Can someone help me out please?</p>