0

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?

1 Answer 1

1

You have to use subscribe or toPromise

return this.http.post<any>(URL + this.url, record)
  .pipe(
    ...
  ).toPromise();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.