title: $dirty property is back to true even after calling $setPristine() in the $scope
body: <p>I am stuck on something that might sounds a JS asynchronous problem. I am developing an AngularJS application, and when the user types any form data but moves to another page without saving, the app is able to ask whether s/he wants to save it before redirecting to the next page.
  But, when the saving is successfully completed, the app is still asking the user whether s/he wants to save it, again (<strong>bug</strong>), because the conditional statement</p>
  
  <pre><code>if($scope[attrs["name"]].$dirty)
  </code></pre>
  
  <p>is true even after I call $setPristine in my save() function.</p>
  
  <p>Here it is my directive:</p>
  
  <pre><code>app.directive('formConfirmation', function($modal){
  
      return function($scope, attrs){
         $scope.$on('$locationChangeStart', function(event, next, current){
              if($scope[attrs["name"]].$dirty){ // the problem happens right here
                  /* open modal for confirmation */
                  /* and checks whether the user wants to save the dirty form */
                  modalInstance.result.then(function(answer){
                      if(answer){
                          $scope.save();
                      }
                  });
              }
        });
     }
  });
  </code></pre>
  
  <p>And my controller's save function is like this:</p>
  
  <pre><code>$scope.save = function(){
     /* calling a service from a factory to save the record... */
     utils.save($scope.record, function(data){
         // saving was successfully completed
         $scope.myForm.$setPristine(); // $dirty value is set to false
         $location.path('/main');
     }, function(dataError){
         // saving has failed
     });
  }
  </code></pre>
  
  <p>And my HTML:</p>
  
  <pre><code>&lt;form name="myForm" ng-controller="myCtrl" form-confirmation&gt;
     &lt;!-- Form fields here --&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>I imagine the problem happens when I change the path location inside the save function, firing the $locationChangeStart event once again. However when I check the $dirty property of my form the second time, its value is back to true even after calling $setPristine in my save() function.</p>
  
  <p>I am not sure what is happening, I am learning js and angularJS, but this asynchronous javascript architecture is always a challenge. Any help, or guidance would be appreciated.</p>