docs(cookbook/adv_forms): simplify example

Pass the `$index` directly to the `removeContact` function, instead of
searching for it in an expensive forEach loop.

Closes #4320
This commit is contained in:
J Bruni 2013-10-08 00:09:06 -03:00 committed by Pete Bacon Darwin
parent 507d8021b1
commit f7fc00841b

View file

@ -38,13 +38,8 @@ detection, and preventing invalid form submission.
$scope.form.contacts.push({type:'', value:''});
};
$scope.removeContact = function(contact) {
var contacts = $scope.form.contacts;
for (var i = 0, ii = contacts.length; i < ii; i++) {
if (contact === contacts[i]) {
contacts.splice(i, 1);
}
}
$scope.removeContact = function(index) {
$scope.form.contacts.splice(index, 1);
};
$scope.isCancelDisabled = function() {
@ -83,7 +78,7 @@ detection, and preventing invalid form submission.
<option>IM</option>
</select>
<input type="text" ng-model="contact.value" required/>
[ <a href="" ng-click="removeContact(contact)">X</a> ]
[ <a href="" ng-click="removeContact($index)">X</a> ]
</div>
<button ng-click="cancel()" ng-disabled="isCancelDisabled()">Cancel</button>
<button ng-click="save()" ng-disabled="isSaveDisabled()">Save</button>