Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

copy() throws exception if destination is a Resource #1689

Closed
lhorie opened this issue Dec 10, 2012 · 4 comments
Closed

copy() throws exception if destination is a Resource #1689

lhorie opened this issue Dec 10, 2012 · 4 comments

Comments

@lhorie
Copy link

lhorie commented Dec 10, 2012

Stack trace:

Error: destination.push is not a function
copy@file:///C:/test/angular.js:556
ResourceFactory/</Resource[name]/<@file:///C:/test/angular-resource.js:389
qFactory/defer/deferred.promise.then/wrappedCallback@file:///C:/test/angular.js:6650
qFactory/ref/<.then/<@file:///C:/test/angular.js:6687
Scope.$eval@file:///C:/test/angular.js:7840
Scope.$digest@file:///C:/test/angular.js:7707
Scope.$apply@file:///C:/test/angular.js:7926
done@file:///C:/test/angular.js:8933
completeRequest@file:///C:/test/angular.js:9073
createHttpBackend/</<@file:///C:/test/angular.js:9023
createHttpBackend/jsonpReq/doneWrapper@file:///C:/test/angular.js:9085

file:///C:/test/angular.js
Line 5582

@pkozlowski-opensource
Copy link
Member

@lhorie Leo, would you mind providing a jsFiddle / plunk with the reproduce code? What is the AngularJS version we are talking about here?

@pkozlowski-opensource
Copy link
Member

Oh, I think I understand what is going on. Essentially you are bumping into the same issue as:
#1044

Seems like you are trying to do a query method that should return an array but your back-end returns something that is not an array. With $resource you need to make sure that the type of data returned is the same as the expected type (array or object) in the $resource definition.

Closing this one for now, please post something on the mailing list if you need further help with using $resource.

@lhorie
Copy link
Author

lhorie commented Dec 11, 2012

re: reproduction steps: using Angular 1.0.3

http://jsfiddle.net/QH9uG/

@pkozlowski-opensource
Copy link
Member

OK, had to clean up your jsFiddle a bit to see what is going on: http://jsfiddle.net/f6DEQ/7/

As suspected your get action doesn't expect an array but your back-end returns an array. So you either need to specify isArray on your action level as described here: http://docs.angularjs.org/api/ngResource.$resource or have your back-end return an object. Not sure what you are expecting as a result so hard to advice more.

Anyway, it sounds more like a general question about AngularJS usage and not a bug report / feature request. As such would be better asked on the mailing list (https://groups.google.com/group/angular) or the IRC (#angularjs) channel. The mailing list is very active and people there will be happy to help.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants