title: Angular JS - differentiating between a save and update with a common template
body: <p>I am working on a project with a PHP backend and Angular 1.x on the front end. I have a Listings model and I use a common template to create (add) and update (edit) a Listing.</p>
  
  <p>Since eidt and add both use the same front end template I need to be able to detect when a user is creating and when they are editing. It seems there are several ways to do this:</p>
  
  <ol>
  <li><p>I could pass a paramater in the ng-submit:</p>
  
  <pre><code>ng-submit="saveListing({{isNewListing}}"
  </code></pre></li>
  </ol>
  
  <p>Then I could read the value of the paramter in my controller, but I think this is overkill?</p>
  
  <ol start="2">
  <li><p>When editing a Listing some variables set for the form auto-fill</p>
  
  <pre><code>$scope.listing.id = x;
  </code></pre></li>
  </ol>
  
  <p>Therfore I could just check for a value in the above:</p>
  
  <pre><code>$scope.saveListing = function() {
      if(listing.id) {
           // update action
      } else {
           // save action
      }
  };
  </code></pre>
  
  <p>Is the second option a sound and non-hacky approach. I am not an Angular pro so although it seems the logical approach to me I want to ensure that I am not hot woring this.</p>