客户列表.component.ts
onLoadCustomers() { const customerReq = this.customerService.getCustomers()
客户.servise.ts
getCustomers(参数:任意):Observable { 返回 this.http.post(
${this.api}api/v1/customers/query
, params)
}
解决方案1:
onLoadCustomers() { const customersReq = this.customerService.getCustomers({})
即使您不想添加任何参数来调用服务中的函数 需要一个参数,你可以简单地传递一个空对象作为参数。
解决方案2:
getCustomers(params?: any): Observable { return this.http.post(${this.api}api/v1/customers/query, params || {}) }
您还可以通过添加“?”来使参数可选。但在这种情况下,如果“params”未定义,您需要提供默认值。