I want to add input field dynamically and ng-model must be in the below structure. I also want to delete items from array.
Expected Json
{
"Animals": {
"animal": [ "dog","cat","lion" ]
}
}
View
<div ng-repeat="x in selected.Animals.animal">
<button ng-hide="$first" ng-click="removeChoice($index)">remove</button>
<input type="text" ng-model="x"/>
<button ng-show="$last" ng-click="addNewChoice(x)">addnew</button>
</div>
Controller
$scope.selected={};
$scope.selected.Animals= {};
$scope.selected.Animals.animal=[""];
$scope.addNewChoice = function (x) {
$scope.selected.Animals.animal.push(x);
};
$scope.removeChoice = function (index) {
$scope.selected.Animals.animal.splice(index, 1);
};
Here is the workarea