我的错误:错误 TS2554:预期 1 个参数,但得到 0 。这是:未提供“params”的参数

问题描述 投票:0回答:1

客户列表.component.ts

onLoadCustomers() { const customerReq = this.customerService.getCustomers()

客户.servise.ts

getCustomers(参数:任意):Observable { 返回 this.http.post(

${this.api}api/v1/customers/query
, params) }

angular typescript angular7 angular8 viewchild
1个回答
0
投票

解决方案1:

onLoadCustomers() { const customersReq = this.customerService.getCustomers({})

即使您不想添加任何参数来调用服务中的函数 需要一个参数,你可以简单地传递一个空对象作为参数。

解决方案2:

getCustomers(params?: any): Observable { return this.http.post(${this.api}api/v1/customers/query, params || {}) }

您还可以通过添加“?”来使参数可选。但在这种情况下,如果“params”未定义,您需要提供默认值。

© www.soinside.com 2019 - 2024. All rights reserved.