title: AngularJS form inputs: how to set default values based on $scope but bind to new form model
body: <p>Building a CMS with node, mongoDB &amp; angularjs.  I have an edit form with inputs that I want to bind to the $scope so their values are populated with existing data.   Ex: </p>
  
  <pre><code>&lt;form ng-submit="editArticle(article._id, article)" class="edit-form"&gt;
      &lt;label for="hed"&gt;Hed: &lt;input type="text" name="hed" ng-model="article.hed" value="{{article.hed}}" /&gt;&lt;/label&gt;
      &lt;label for="dek"&gt;Dek: &lt;input type="text" name="dek" ng-model="article.dek" placeholder="{{article.dek}}" /&gt;&lt;/label&gt;
      &lt;input type="submit" value="Save Changes"&gt;&lt;/input&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>This appropriately fills in the input values with the current data from my mongo database.  However, I would like to bind to a new form scope, so it doesn't try to pass in every value in the article scope, just the new scope within the form. (Article scope currently consists of every field in the article document in Mongo.  If I pass all of this data in, I get an error about invalid schema because it is trying to pass in the __v field as well.)</p>
  
  <p>So ideally I want to do this:</p>
  
  <pre><code>&lt;form ng-submit="editArticle(article._id, form)" class="edit-form"&gt;
      &lt;label for="hed"&gt;Hed: &lt;input type="text" name="hed" ng-model="form.hed" value="{{article.hed}}" /&gt;&lt;/label&gt;
      &lt;label for="dek"&gt;Dek: &lt;input type="text" name="dek" ng-model="form.dek" placeholder="{{article.dek}}" /&gt;&lt;/label&gt;
      &lt;input type="submit" value="Save Changes"&gt;&lt;/input&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>So on submit, it only passes form.hed and form.dek to my database.  However, now these input fields are blank because they're not bound to the original article data. The user would have to re-fill in each of the fields with the original values.  Is there a way to bind to multiple models orrrr bind to a current model, but on submit only send the updated form data?  </p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>It looks like I have to add the ng-change attribute to each field, to populate the input fields with the original scope, then on change, set the form scope equal to the changed value.  Eg.  </p>
  
  <pre><code>&lt;form ng-submit="editArticle(article._id, form)" class="edit-form"&gt;
      &lt;label for="hed"&gt;Hed: &lt;input type="text" name="hed" ng-change(form.article = article.hed) ng-model="article.hed" /&gt;&lt;/label&gt;
      &lt;label for="dek"&gt;Dek: &lt;input type="text" name="dek" ng-change(form.dek = article.dek) ng-model="article.dek" placeholder="{{article.dek}}" /&gt;&lt;/label&gt;
      &lt;input type="submit" value="Save Changes"&gt;&lt;/input&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>Not sure how thrilled I am about this solution, but it works.  If anyone knows a more efficient way to accomplish this please let me know!</p>