【问题标题】:Problem with getList() in ngx-restangularngx-restangular 中的 getList() 问题
【发布时间】:2019-08-22 10:03:07
【问题描述】:

我正在使用 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)

【问题讨论】:

    标签: angular restangular


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

      如果是 JSON 对象,您需要检查列表的返回类型,然后只接受它,否则 restangular 不接受另一种类型的响应,只接受 JSON 对象。

      【讨论】:

        猜你喜欢
        • 2023-03-22
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-08-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多