json - Adding ng-model values as grouped children in array -


learning python has made me forget angular, , that's story , i'm sticking it. it's made me forget google skills, since can't find similar question anywhere. closest might how append json object in angular js, except didn't work, either.

i've got ten sets of 2 input fields, title , description. want add them children array, i'll end ten properties in json, , each property in turn has 2 children properties. i've tried push, concat, old-fashioned += in desperation, nothing's working. must totally missing obvious.

here's each row looks like, though numbers change (from 1 10):

<label class="sr-only" for="shorttitle1">short title</label> <input type="text" class="form-control"  ng-click="addidea()" ng-model="idea1.title" placeholder="title"> <label class="sr-only" for="description1">description</label> <input type="text" class="form-control" ng-click="addidea()" ng-model="idea1.description" placeholder="description"> 

in controller, here's version i've tried based on link above, isn't working better concat or push did:

$scope.ideas = [         {idea : $scope.idea1.title, $scope.idea1.description},         {idea : $scope.idea2.title, $scope.idea2.description},         {idea : $scope.idea3.title, $scope.idea3.description} ]; 

i keep getting error of unexpected token dots (as in, dot in $scope-dot-idea1). when put in simple text test, unexpected token error closing bracket.

i've tried doing watchcollection, see if controller pay attention, i'm getting nothing that. i've tried watching idea1, $scope.idea1, $scope.idea1.title, , watchcollection sits there.

this want end looking like, roughly:

$scope.ideas = [     {         type : 'title goes here',         description : 'description goes here'     },{         type : 'title goes here',         description : 'description goes here'     },{         type : 'title goes here',         description : 'description goes here'     } ]; 

i've checked obvious -- ng-app isn't on same level ng-controller, i'm calling right controller, don't have wacky misspellings.

help?

you missed description key off object definitions.

$scope.ideas = [     {idea : $scope.idea1.title, desc: $scope.idea1.description},     {idea : $scope.idea2.title, desc: $scope.idea2.description},     {idea : $scope.idea3.title, desc: $scope.idea3.description} ]; 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -