ketan
ketan

Reputation: 19341

Response status code getting null Angular

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.

Upvotes: 0

Views: 749

Answers (1)

jitender
jitender

Reputation: 10429

You will need to observe response something like

this.http.post<any>(`this.endpointUrl?eventId=${pId}&email=${email}`,"",{observe: 'response'})

Upvotes: 1

Related Questions