In the process of creating a dynamic form with add/remove functionality, I experimented with utilizing ng-model
within ng-repeat
. Here is an example of what my code entails:
<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);
};
However, this approach resulted in all input fields being synchronized and displaying identical content for each item in the array, which was not my intended outcome. For reference, a working sample of my code can be found on codepen.