I am using AngularJS v1.5.8.
In html
<div class="form-group row" data-ng-repeat="friend in friends track by $index">
<label class="col-xs-1 control-label">Friend </label>
<div class="col-xs-2">
<input type="text" class="form-control" required ng-model="friend.first_name" placeholder="First Name" />
</div>
<div class="col-xs-2">
<input type="text" class="form-control" required ng-model="friend.last_name" placeholder="Last Name" />
</div>
<div class="col-xs-4">
<input type="email" class="form-control" required ng-model="friend.email" placeholder="Email" />
</div>
<div class="col-xs-2">
<input type="text" class="form-control" ng-model="friend.phone" placeholder="Phone" />
</div>
<div class="col-xs-1">
<a href="#" ng-click="addMore($index)"><span class="glyphicon glyphicon-plus"></span></a>
</div>
<div class="col-xs-1">
<a href="#" ng-click="removeFriend($index)"><span class="glyphicon glyphicon-remove"></span></a>
</div>
<div class="clearfix"></div>
In controller
$scope.friends = [{first_name: "", last_name: "", email: "", phone: ""}];
$scope.addMore = function () {
console.log('in add');
$scope.friends.push({
first_name: "",
last_name: "",
email: "",
phone: ""
});
};
$scope.removeFriend = function(index) {
console.log("in remove: "+index);
$scope.friends.splice(index,1);//delete last row in html form..am I expecting something wrong....
};
while I inspect the code I get removeList($index) instead I was hoping removeList(1) or removeList(4).
What possibly can be wrong?
I have two questions - why even if I am passing index correctly , it end up deleting last element - how data entered will be updated in angular...
If you have some tutorial to follow please share the link
$indexin the scope ?$scope.list.splice(referIndex,1);should be$scope.lists.splice(referIndex,1);