Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit f7fc008

Browse files
jbrunipetebacondarwin
authored andcommitted
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
1 parent 507d802 commit f7fc008

File tree

1 file changed

+3
-8
lines changed

1 file changed

+3
-8
lines changed

docs/content/cookbook/advancedform.ngdoc

+3-8
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,8 @@ detection, and preventing invalid form submission.
3838
$scope.form.contacts.push({type:'', value:''});
3939
};
4040

41-
$scope.removeContact = function(contact) {
42-
var contacts = $scope.form.contacts;
43-
for (var i = 0, ii = contacts.length; i < ii; i++) {
44-
if (contact === contacts[i]) {
45-
contacts.splice(i, 1);
46-
}
47-
}
41+
$scope.removeContact = function(index) {
42+
$scope.form.contacts.splice(index, 1);
4843
};
4944

5045
$scope.isCancelDisabled = function() {
@@ -83,7 +78,7 @@ detection, and preventing invalid form submission.
8378
<option>IM</option>
8479
</select>
8580
<input type="text" ng-model="contact.value" required/>
86-
[ <a href="" ng-click="removeContact(contact)">X</a> ]
81+
[ <a href="" ng-click="removeContact($index)">X</a> ]
8782
</div>
8883
<button ng-click="cancel()" ng-disabled="isCancelDisabled()">Cancel</button>
8984
<button ng-click="save()" ng-disabled="isSaveDisabled()">Save</button>

0 commit comments

Comments
 (0)