I have this service:

function fileManagerClient($resource, $http, $rootScope, dataService) { var userId = $rootScope.globals.currentUser.userId; var kpeId = $rootScope.kpeId; var fileName = "8888"; return $resource("api/file/:userId/:kpeId/:fileName", { fileName: "@fileName" }, { 'query': { method: 'GET', params: { userId: '@userId', kpeId: '@kpeId', fileName: fileName } }, 'save': { method: 'POST', params: { userId: userId, kpeId: kpeId, fileName: fileName }, transformRequest: angular.identity, headers: { 'Content-Type': undefined } }, 'remove': { method: 'DELETE', params: { userId: userId, kpeId: kpeId, fileName: fileName } } }); } 

And there is another service that calls the query, save, remove methods of the fileManagerClient service.

When I enter the page, the query method is called. Fulfills a method in WebApi and get an error

result: [$ resource: badcfg] query http://errors.angularjs.org/1.5.8/$resource/badcfg?p0=array&p1=object&p2=GET&p3=api%2Ffile%2F8e845a58-2bca-4879-8cde-7ce90b49490c% 2Ffe90aad5-55ea-4f23-baeb-f66afd387e45% 2Ftest

How to configure $resource to run all the methods (query, save, remove)?

  • no, everything is very bad. remove your load and remove, and add a server method which by query Must be called - Grundy
  • why is he here? - endovitskiiy
  • so that you can see exactly what you are returning to it. Now you say that you have a mistake because you are returning an object. And in the answer I said again to wait for the array - Grundy
  • Do not mind it. In my case, the object is returned, and in the code I have isArray: false . I'll change the answer now. Just as a correct answer here, in my opinion, it doesn’t matter. There, even in the text of the error, they say that an array is expected and the object has come, or vice versa. - endovitskiiy
  • It is just a matter of principle that the error states that an object has arrived, and you are waiting for an array. And in the answer you write what type - now I’m definitely waiting for the array :-) that is, it’s not at all clear what exactly was decided - Grundy

1 answer 1

Passing through the link in the text of the error, I realized that the $resource service expects an object as a response, and I returned an array.

Solution: add the isArray: false parameter to the 'query' isArray: false

Final version: 'query': { method: 'GET', params: { userId: '@userId', kpeId: '@kpeId', fileName: fileName }, isArray: false}

Everything worked as it should.

  • добавить параметр isArray: true , Final version: isArray: false :) you have to decide - Grundy
  • did not guess :-) your server returns the object! - Grundy
  • now correct?) - endovitskiiy
  • Well, it's your code :-D just copy from the real code as you did. - Grundy