There is a service with post-request:

postData(data: any) { return this.http.post('http://localhost:8080', data); } 

I register it in a component. I want to use it. I pass it to the method:

 sendCsvFile() { const formData = new FormData(); formData.append('csv-file', this.selectedFile, this.selectedFile.name); this.http.postData(formData, { reportProgress: true, observe: 'events' })... 

But I can not, gives this error:

error TS2554: Expected 1 arguments, but got 2.

  • Why is postData called via this.http ? - Nick
  • Sorry, did not write. constructor (private http: HttpClient) {} - Nikolai Gavrilov

1 answer 1

The described method takes only one parameter:

 postData(data: any) { 

with the name data .

When calling: this.http.postData(formData, {...}) , an attempt is made to pass 2 parameters.

Therefore, you need to either change the method signature or pass only one parameter.

  • thanks for the answer. Sent back on track. Dull stupidity)))) on my part. - Nikolai Gavrilov