Hi I am new to Angularjs please help i am trying to create a dynamic form field my html is like this
<div ng-repeat="cb in categories">
<div ng-repeat="choice in cb.choices">
<input type="text" ng-model="choice.req_goods">
<input type="text" ng-model="choice.qty">
<button ng-hide="$first" ng-click="removeChoice($parent.$index,$index)">-</button>
</div>
<button type="button" ng-click="addNewChoice($index)">+</button>
</div>
js
$scope.categories = [
{
"id":1,
"name":"Furniture & Fixture",
"choices":[
{
"req_goods":"table",
"qty":"4"
}]
},
{
"id":2,
"name":"Miscellaneous Property",
"choices":[
{
"req_goods":"others",
"qty":"6"
}]
}];
$scope.addNewChoice = function(id){
$scope.categories.choices[id].push({});
};
I want to add choices dynamically when user click add button. I tried above addNewChoice() function but it gives error angular.min.js:114 TypeError: Cannot read property '0' of undefined" please help i am really tense as i am trying this from yeterday. thank you
$scope.categories[id].choices.push({ "req_goods":"", "qty":"" });