0

I implemented post method in angular 7. I want status code of post request.

I did following.

const sub = this.service.regEvent(this.pId, this.email)
      .subscribe(response => {
        console.log('response:', response);
        if(response.httpStatusCode === 200) {
        }
});

this.subscriptions.push(sub);

regEvent method

public regEvent(pId, email): Observable<any> {
    return this.http.post<any>(`this.endpointUrl?eventId=${pId}&email=${email}`,"").pipe(
      catchError(this.handleError)
    );
  }

Here console.log('response:', response); I am getting null.

In browser i checked and it's.

enter image description here

In postman also.

enter image description here

any help would be greatly appreciated.

ketan
  • 19,129
  • 42
  • 60
  • 98
  • It's unclear why you *expected* `httpStatusCode` to be there. That's not what the property is called even if you *do* read the full response [as the docs tell you](https://angular.io/guide/http#reading-the-full-response). If you used a better type than `any` to describe the actual response, the compiler could help you out. – jonrsharpe Sep 13 '19 at 10:57

1 Answers1

1

You will need to observe response something like

this.http.post<any>(`this.endpointUrl?eventId=${pId}&email=${email}`,"",{observe: 'response'})
jitender
  • 10,238
  • 1
  • 18
  • 44