If I’m building an index page for a blog in AngularJS with comments like this:
<li ng-repeat="post in posts">
<h2>{{post.title}}
<p>{{post.description}}</p>
<h3>Leave a comment</h3>
<form ng-submit="postComment()">
<input type="hidden" value="{{post.id}}">
Name: <input type="text"> <br>
Comment: <textarea></textarea> <br>
<input type="submit" value="Post comment">
</form>
</li>
I can’t figure out what the right way is to associate a model with the form to access from the controller’s postComment() function. If you use just one model for all the forms, then starting to leave a comment on one post will start to leave a comment on all of them—unless you do some weird stuff with the hidden post.id field, but that starts to feel unidiomatic.
You can pass an object into the function call.
As far as the other inputs, it really depends on the situation, but in this case, the
inputandtextareais inside anngRepeat, which creates new scope. For that reason, assigning to a value on the scope will not affect other elements on the page.