angular - 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)
解决方案
一直都是这样,这是正常的行为。getList 方法需要一个数组作为其结果。相反,如果您想调用返回对象的 API(带或不带分页),则必须使用 get 方法,然后将结果映射到所需的模型类中。
推荐阅读
- r - 如何将 .RData 直接保存在不同的对象中?
- jquery - 尝试从其他域获取 json 数据时未定义
- java - 带有可选参数的 REST GET API - 设计和实现
- gulp - 如何使用 Browserify 和 coffeeify 转换将 CoffeeScript 转换为 JavaScript(最后 2 个版本,即 >= 11)?
- maven - 子项目找不到具有 relativePath 的父项
- windows - 如果选项以 hypen 开头,则批处理文件命令行参数解析错误
- java - 使用套接字和 XMPP 发送消息
- reactjs - 如何创建 React Native Navigation 路线?
- ruby-on-rails - 在 Ruby on rails 中使用 CarrierWave 文件上传时 Imagemagick 的安装链接
- angularjs - 如何将颜色设置为 Angular-nvd3 (1.0.7)