【问题标题】:Angular API Call doesn't get called没有调用 Angular API 调用
【发布时间】:2021-06-14 10:19:36
【问题描述】:

这是我的代码。当从组合框中选择一个属性时,我试图显示一个列表。我从后端获取列表,但是每当我单击显示按钮时都会收到此错误。尽管如此,该方法是GET 方法。可能是什么问题?

TS:

filter() {
    this._stockService
      .getWarehouseTransferReport()
      .subscribe((response: any) => {
        this.dataSource = new MatTableDataSource(response);
        this.dataSource.paginator = this.paginator;
        this.dataSource.sort = this.sort;
        this.dataSource.filterPredicate = (data, filter) =>
          this.filterPredicate(data, filter);
      });
  }


  filterPredicate(data: IWarehouseTransferItem, filter: string) {
    let searchText = data.Reference;
    if (data.Reference) {
      searchText += (data.Reference as any).toLocaleLowerCase("tr");
  }
    if (data.DeliveryNote) {
        searchText += (data.DeliveryNote as any).toLocaleLowerCase("tr");
    }
    if (data.StockIntegrationCode ) {
        searchText += (data.StockIntegrationCode  as any).toLocaleLowerCase("tr");
    }
    if (data.Product.ProductName) {
        searchText += (data.Product.ProductName as any).toLocaleLowerCase("tr");
    }

    return searchText.indexOf(filter) >= 0;
}

服务 TS:

getWarehouseTransferReport(): Observable<IWarehouseTransferItem[]> {
    return this._http.get("Stock/GetWarehouseTransferReport");
}

后端 C#:

 /// <summary>
        /// TRANSFER REPORT
        /// </summary>
        /// <param name="producdId"></param>
        /// <returns></returns>
        [HttpGet]
        public List<DtoWarehouseTransferItem> GetWarehouseTransferReport(int producdId)
        {
            return WarehouseSpProvider.GetWarehouseTransferReport(producdId);
        }
    }

【问题讨论】:

  • 您是否尝试使用 Postman 调用 GetWarehouseTransferReport API 并查看结果?

标签: javascript html angular typescript get


【解决方案1】:

这可能意味着服务器知道方法但不支持目标源。这是参考Mozilla link
所以基本上这不是 Angular Http 客户端的问题。

参考链接,其中显示了有关 405 状态代码问题的许多详细信息。 Link

【讨论】:

    【解决方案2】:

    您的 C# 后端代码需要一个参数 int productId,但我认为您没有传递任何参数,这就是现在调用它的原因。

    【讨论】:

      【解决方案3】:
      • 可能是您传递了错误的对象或对象的值不匹配。
      • 可能是数据类型问题或参数计数问题以及您的 API 需求 正确的对象和价值。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2021-10-20
        • 2019-05-17
        • 2021-11-06
        • 2017-08-28
        • 2012-09-02
        • 2018-12-30
        • 2021-09-11
        相关资源
        最近更新 更多