I have an Object representing a "discussion" or a "debate" that has two children -- each child is a collection of child objects representing "contentions" in the debate. One child is a collection of "affirmative" contentions, the other is of "negative" contentions.
I'm using something like this:
<div ng-controller="contentionGroupCtrl" ng-repeat="(contentionType, contentionGroup) in debate.contentions_sorted" class="contention {[{contentionType}]}-section">
<a class="button contention-new" ng-click="toggleEditForm()">+ Add New Contention</a>
<div class="contention-new" ng-show="editing">
<form ng-submit="formContentionSubmit()" class="ng-scope ng-pristine ng-invalid ng-invalid-required">
<input type="text" id="contention_name" name="contention[name]" required="required" ng-model="edit.name" placeholder="New Contention" class="ng-pristine ng-invalid ng-invalid-required">
<div>
<input type="radio" id="contention_aff_0" name="contention[aff]" required="required" ng-model="edit.aff" value="1">
<label for="contention_aff_0" class="required">Affirmative</label>
<input type="radio" id="contention_aff_1" name="contention[aff]" required="required" ng-model="edit.aff" value="0">
<label for="contention_aff_1" class="required">Negative</label>
</div>
<input type="button" ng-click="toggleEditForm()" value="Cancel">
<input type="submit" value="Save">
</form>
</div>
<div ng-controller="contentionCtrl" ng-repeat="contention in contentionGroup" class="contention" id="contention-{[{ contention.id }]}">
EACH CONTENTION CONTENT STUFF HERE
</div>
</div>
This displays two sets of contention, and each has a "Add New Contention" form at the top. The form is toggled based on the toggleEditForm() method. I'm using the same form template for "New Contention" and "Edit Contention", and hence that form has a model (radio buttons) for whether the contention is an "Affirmative" or "Negative" contention.
The controller "contentionGroupCtrl" is for the group of contentions, and its toggleEditForm method looks like this:
// Toggle New Contention Form
$scope.toggleEditForm = function() {
var ct;
$scope.editing = !$scope.editing; // First display or hide the form
if ($scope.editing == true) { // If displaying the form, initialize
if ($scope.contentionType == 'aff') {
ct = 1; // 'aff' equates to 1 in the model
}
else {
ct = 0;
}
$scope.edit.aff = ct; // Sets the radio button appropriately
// We are now editing
$scope.edit.name = ''; // Blanks out the contention "Name" field for creating a new contention
}
};
Everything works great, except: Let's say you open the "Affirmative"-side "Add New Contention" form. It will present a blank Name, with the radio button "Affirmative" selected. If you then click the "Negative"-side "Add New Contention" button, the appropriate form will appear, but both "Name" fields will be blanked out, and the radio button will be selected for "Negative" in both.
$scope should be different on each side, shouldn't it? Each form uses its own $scope.edit model; why should modifying the Negative contention side's "edit.name" and "edit.aff" models affect the Affirmative side's?