Getting an error in AngularJS parsing my json data

1,669 views
Skip to first unread message

cord....@gmail.com

unread,
Nov 3, 2012, 3:30:05 PM11/3/12
to ang...@googlegroups.com
I have valid json data that combines an array of people with two meta fields (see attached graphic).  I do this because my service either returns up to 1000 people in a json array or generates a CSV file for pickup on the web server.   Well, i am getting an error here:  

TypeError: Object #<Resource> has no method 'push' at copy (http://localhost:8888/phonecat/app/lib/angular/angular.js:556:21)

The json returned is basically:

{"peoples":[{"fname":"Cord","lname":"Thomas","angularskills":"newb"},{"fname":"Other","lname":"Person","angularsills":"expert"}],"datatype":"people","outputtype":"json"}

Any thoughts on what i might do to correct this. I recognize this is not an angular issue, but looking for some guidance on how i might structure this to parse properly.

My goal is that in the template, i would read the outputtype as (json|csv) and present accordingly, either a list of people or a link to the csv file...

Appreciate your help with this!

Cord
Screen Shot 2012-11-03 at 12.20.15 PM.png

Thierry Chatel

unread,
Nov 4, 2012, 4:04:50 AM11/4/12
to ang...@googlegroups.com, cord....@gmail.com
I think it's a problem in your use of $resource.

Use get action (which implies isArray:false) when the server returns a json object.
Use query action (which implies isArray:true) when the server returns a json array.

You'll find some information here : https://github.com/angular/angular.js/issues/1044


cord....@gmail.com

unread,
Nov 4, 2012, 12:04:40 PM11/4/12
to ang...@googlegroups.com, cord....@gmail.com
Thank you Thierry

Indeed that was the issue. Rather than change the action, i was able to change the isArray:false as  others had suggested in github.  Probably for readability, i should change to using get, but still learning and do not want to change that many things at once.

Appreciate it.
Reply all
Reply to author
Forward
0 new messages