【问题标题】:I have to display data in a modal. For this I am using an Angular2 service and consuming web service to display from a backend DB. In我必须以模式显示数据。为此,我使用 Angular2 服务并使用 Web 服务从后端数据库显示。在
【发布时间】:2018-01-16 09:05:16
【问题描述】:

您好,我必须以模式显示数据。为此,我使用 Angular2 服务并使用 Web 服务从后端数据库显示。这样做时,我收到以下 2 个错误。

1) 加载资源失败:服务器响应状态为500() 2) 错误类型错误:您在预期流的位置提供了无效对象。您可以提供 Observable、Promise、Array 或 Iterable

下面是 Angular2 服务,后面是 Angular2 方法。请帮我解决这个问题。所有这些输出列表/数据数组。

Angular2 服务

产品服务

     public GetProductInfo(prodId, depId, custId): Observable<any> {
          let myParams = new URLSearchParams();
          myParams.append('prodId', prodId);
          myParams.append('depId', depId);
          myParams.append('custId', custId);
          let options = new RequestOptions({ params: myParams });
          return this.commonService.get(this.GetProductEndpoint, options);
}

component.ts 中的 Angular2 方法

private loadGetProductInfo(prodId: any, depId: any, custId: any) {
  this.productsService.GetProductInfo(prodId, depId, custId)
    .subscribe((result) => {
      if (result != null) {
        this.GetProductInfo = result;
        this.temp = [...result];
        this.productsInfo = result;
      }
    });
}

【问题讨论】:

    标签: angular angular2-services


    【解决方案1】:

    您的后端抛出了一个错误,而产生的错误没有得到适当的处理,从而导致了第二个错误。

    GetProductInfo 期望从您的 get 请求中返回一个 observable,但您的 get 请求失败,不处理异常(错误),并且不返回引发错误的 observable。

    【讨论】:

    • 嗨,谢谢 Nikola...所以我的代码在调用服务时没有问题,但我没有进行错误处理...我说得对吗?
    • @nirajak 是的,您的角度代码正在中断,因为您的服务器代码正在中断。修复你的后端服务器代码和你的角度代码应该被修复。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-24
    相关资源
    最近更新 更多