I'm creating a form that has add/remove function. To achieve that, I tried to use ng-model
in ng-repeat
. Here's what my code looks like.
<button ng-click='add()'>Add more</button>
<div ng-repeat='x in array track by $index'>
<input ng-model='array[$index].name'></input>
<input ng-model='array[$index].phone'></input>
<input ng-model='array[$index].email'></input>
</div>
//angular module
$scope.add = function () {
$scope.array.push(item);
};
But then, all input field will be synchronized and all the item in the array looks the same, which is what I don't intend to. Also, I made a sample of my code in codepen.