My code on jsfiddle.
HTML
<div ng-controller="MyCtrl">
<input>
<button ng-click='add()'>Add</button>
<br/>
<b>Items Added Below</b>
<div ng-repeat='item in items'>
<input ng-model='item' id='item-{{$index}}' class='input-{{$index}}'/>
<button ng-click='del($index)'>DEL</button>
</div>
</div>
Angular Controller
var myApp = angular.module('myApp',[]);
function MyCtrl($scope) {
$scope.items = [];
$scope.newitem = '';
$scope.add = function(){
if ($scope.items.length < 4) {
$scope.items.push($scope.newitem);
}
}
$scope.del = function(i){
$scope.items.splice(i,1);
}
}
I try to dynamic add input by ng-click and remove specific but always delete last input..
I think its because they are not distinguish in items array.
How I can fix this ?