Answer the question
In order to leave comments, you need to log in
How to get correct response from API? Error: [filter:notarray] Expected array but received?
I need to send a request to the API and get a response in the following form
workers: Array[2]
count_items: 2
Error: [filter:notarray] Expected array but received:
{"workers":
[{"id":15,"user_id":17,"company_id":20,"created_at":"2016-04-08T10:15:59.775Z","updated_at":"2016-04-08T10:15:59.775Z","info":{"first_name":"George","last_name":"Lucas","email":"[email protected]"},"deleted_at":null,"name":"dsadsa dsadsa"},
{"id":16,"user_id":5,"company_id":20,"created_at":"2016-04-08T10:16:08.446Z","updated_at":"2016-04-08T10:16:08.446Z","info":{"first_name":"Sam","last_name":"Mitch","email":"[email protected]"},"deleted_at":null,"name":"dsad dsadas"}],
"count_items":2}
class CompanyWorkersController < ApplicationController
def index
render json: { workers: company.company_workers.page(params[:page])
.as_json(methods: :name),
count_items: company.company_workers.length }
end
end
factory('CompanyWorkers', [
'$resource', function($resource) {
return $resource('/company_workers/:id/:action', {id: '@id'},
{ 'query': { isArray: false } }
);
}
]);
CompanyWorkers.query({ page: options.page }, function(response) {
console.log(response);
});
Answer the question
In order to leave comments, you need to log in
It's not about $recourse, it works correctly.
The filter throws an error. https://github.com/angular/angular.js/issues/9992#...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question