mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-03-17 07:40:22 +00:00
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:
parent
507d8021b1
commit
f7fc00841b
1 changed files with 3 additions and 8 deletions
|
|
@ -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>
|
||||
|
|
|
|||
Loading…
Reference in a new issue