-1

I am using HttpClient and it doesn't make a network request, there are no errors so I don't know what is wrong.

  postFile(file: FileUpload) {
    console.log('posting file');
    return this.http.post(this.apiRoot + '/api/file', file, this.httpOptions)
      .pipe(
        catchError(this.handleError('postFile', []))
      );
  }

app.module

import { HttpClientModule } from '@angular/common/http';
// ...
imports: [
    HttpClientModule
  ],
matt
  • 659
  • 2
  • 8
  • 15

1 Answers1

0

You are missing the subscribe().

return this.http.post(this.apiRoot + '/api/file', file, this.httpOptions)
   .pipe(
      catchError(this.handleError('postFile', []))
   )
   .subscribe();

or in your component call the method like this:

this.postFile(file).subscribe();
XardasLord
  • 1,764
  • 2
  • 20
  • 45