forgottofly forgottofly - 1 month ago 9
Javascript Question

ng-repeat not pushing data

I'm using ng-repeat directive to list a set of JSON data of the format

$scope.result=[
{
"id": 84,
"resource": {
"id": 3,
"name": "Resource Planning",
"description": "test"
},
"activity": {
"id": 6,
"name": "Activity Planning",
"description": "test"
}
}
]


My usage of ng-repeat is like this..

<div ng-repet="data in result">{{data.resource.name}} {{data.activity.name}}</div>


I'm able to display the name ie., "Resouce Planning" and "Activity Planning".
But I can't push the data if I'm doing like this

$scope.result.push({resource.name:result.resource.name,activity.name:result.activity.name})


from the controller.
Is there any way to push the name which is inside the object. And to display/list the same using ng-repeat?
Thanks

Answer

I don't really understand the question, but that's not how you build your javascript object. It should be something like:

$scope.result.push({
       resource: {
            name:   result.resource.name
       },
       activity: { 
            name:   result.activity.name
       }
})