Angular HttpClient not executing with post

bensiu

I have a service class with an Angular application that looks like this:

@Injectable()
export class AbstractStore {
  protected url: string;

  constructor(protected http: HttpClient) {}

  read(url: string): Observable<any> {
    return this.http.get<any>(URL + url).pipe(
      ...
    );
  }

  loadRecords(): Observable<Record[]> {
    return this.read(this.url);
  }

  loadRecord(id: string): Observable<Record> {
    return this.read(`${this.url}/${id}`);
  }

  saveRecord(record: Record): Observable<Record> {
    // console statement executes
    console.log("Saving record..................", URL + this.url, record);

    // THIS NOT EXECUTE
    return this.http.post<any>(URL + this.url, record).pipe(
      ...
    );
  }

  handleError(error) {
    console.log(error.message || error);
  }
}

When calling read (http.get) methods it executes properly and I see traffic in the Network tab. When coming to saveRecord() method - it executes up to console statement. I do not see execution in the Network tab.

I not sure what I am doing wrong?

Ferhado

You have to use subscribe or toPromise

return this.http.post<any>(URL + this.url, record)
  .pipe(
    ...
  ).toPromise();

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Angular HttpClient is not executing

Angular HttpClient post not sending

Angular HttpClient post not working

Angular map HttpClient.Post

Angular 6 httpClient Post with credentials

Angular 5 - HttpClient Post not posting

Angular HTTPClient POST body not sending

Angular - HTTPClient put and post not working

Why HttpClient.Post method is not Executing all the Methods?

angular2: http post not executing

Angular - Defining error type to HttpClient.post()

Angular 12 HttpClient POST to string does not compile

Angular 5 HttpClient post raw binary data

Angular 5 Service httpClient Post - Title is not defined

Angular HttpClient use URL Params in POST

Angular httpClient - POST successful, no parameters sent

Angular 7 HttpClient post response headers are empty

Angular HttpClient: If get() fails, then execute a post()

HTTPClient POST request not working on Angular 5 / Angular Universal

Unable to make HttpClient post request in Angular because of CORS issue

How to send POST request via angular's HttpClient?

Angular 9 - How to refresh form page after HttpClient POST?

Post multidimensional array (string[][]) in angular using HttpClient / HttpParams

Angular HttpClient post cannot send simple string parameter

Angular9 post the data to API by form data with HttpClient

Sending and receiving different Types with httpclient.post in Angular

Angular6 HttpClient Post method not working although Postman is successful?

Angular 8 HttpClient Post Request Content-Type debacle

Angular 5 HttpClient: Send POST params as URL encoded string