Reputation:
I'm using Angular 8.2.0 and ngx-restangular on it. In my service I use getList()
; the following error appears in the console
Error: Response for getList SHOULD be an array and not an object or something else.
I researched and looked at Restangular's methods. I tried to output with get()
instead of getList()
but it didn't work.
getAllBalanceListIssues(context: string, month: string): Observable<SusaList[]> {
let url = `/susa?context=${context}`;
if (month !== null) {
url = `${url}&period=${month}`;
}
return this.restAngular.all(url).getList();
}
core.js:6014 ERROR Error: Response for getList SHOULD be an array and not an object or something else
at SafeSubscriber.okCallback [as _next] (ngx-restangular.js:1363)
at SafeSubscriber.__tryOrUnsub (Subscriber.js:185)
at SafeSubscriber.next (Subscriber.js:124)
at Subscriber._next (Subscriber.js:72)
at Subscriber.next (Subscriber.js:49)
at CatchSubscriber._next (Subscriber.js:72)
at CatchSubscriber.next (Subscriber.js:49)
at MapSubscriber._next (map.js:35)
at MapSubscriber.next (Subscriber.js:49)
at MapSubscriber._next (map.js:35)
Upvotes: 0
Views: 189
Reputation: 1
You need to check your return type of list if it is JSON object then only it is accepted otherwise restangular not accept another type of response only accepts JSON object.
Upvotes: 0
Reputation: 377
It has been always like this and this is the normal behavior. The getList method expects an array as its result. instead if you want to call an API which returns back an object (with or without pagination) you must use the get method and then map the result into your desired model class.
Upvotes: 0