首页 > 解决方案 > ngx-restangular 中的 getList() 问题

问题描述

我正在使用 Angular 8.2.0 和 ngx-restangular。在我的服务中,我使用getList(); 控制台中出现以下错误 Error: Response for getList SHOULD be an array and not an object or something else.

我研究并查看了 Restangular 的方法。我试图用get()而不是输出,getList()但它没有用。

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)

标签: angularrestangular

解决方案


一直都是这样,这是正常的行为。getList 方法需要一个数组作为其结果。相反,如果您想调用返回对象的 API(带或不带分页),则必须使用 get 方法,然后将结果映射到所需的模型类中。


推荐阅读