title: Fundamental misunderstanding of how Angular handles a snippet?
body: <p>I'm having a problem debugging some code in an Angular controller. This function is called when a form is submitted on our checkout page. I'm fairly new to Angular, and I'm a bit confused as to what is going on in this function. </p>
  
  <pre><code>  $scope.handleStripe = function(status, response){
      PayStripe.processPayment(status, response).then(
        function(successMessage){
          alert('success', successMessage);
          Order.recordOrder(Cart.cart.items, Auth.user.uid)
            .then(function(){
              PostAffiliatePro.reportSale(Cart.cart.getTotalPrice());
              Cart.cart.clearItems();
              $scope.mode = 'success';
            });
        }
      );
    };
  </code></pre>
  
  <p>Here's what I think is happening line-by-line...</p>
  
  <p>1) We're declaring a function called <code>handleStripe</code> with two arguments: <code>status</code> and <code>response</code>.<br>
  2) A method called <code>processPayment</code> is being called and is inside of an object dependency injected into the controller called <code>PayStripe</code>. <code>.then</code> is opened, so the following lines of code will be executed AFTER the <code>processPayment</code> method is called.<br>
  3) Running an anonymous function with an argument of <code>successMessage</code>.<br>
  4) I'm  confused as to what's happening here, as I've never seen <code>alert</code> called with any arguments other than a message. <a href="http://www.w3schools.com/jsref/met_win_alert.asp" rel="nofollow">this page on <code>alert</code></a> is not much help.<br>
  5) A method called <code>recordOrder</code> is called from the object <code>Order</code> which is a dependency of the controller.<br>
  6-10) After the <code>recordOrder</code> method is called, the cart is cleared, the sale is reported through another method, and the <code>mode</code> variable contained in the controller's <code>scope</code> is updates to the value <code>success</code>.  </p>
  
  <p>I've looked through all of the methods associated with these steps, and I still have some questions. </p>
  
  <p>1) Where are all of these arguments being passed in? Are the arguments passed into the functions pre-declared arguments that will be updated by Angular? I.E. are these variables which Angular defines as the process moves through the queue, and whose values are not user-defined? 
  2) On line #4, I understand that the second argument is from the argument defined in the function, but what is the combination of these two valued inside the <code>alert()</code> function doing?
  3) The fix to the bug that comes from this script depends on me being able to change the value of <code>$scope.mode</code> to something different as soon as the  <code>handleStripe</code> function is called, however I have tried to insert such a declaration in multiple places that seem logical with results varying from the script breaking, to nothing happening at all. To me it seems that the logical place to put <code>$scope.mode = 'my-value';</code> would be between current lines #1 and #2, however this produces the affects I mentioned before. </p>
  
  <p>Finally, I feel I may be missing an overall concept, rather than wrestling with syntax. What is this concept called, if I am missing one, and where can I learn to use it?</p>