Skimar
Skimar

Reputation: 129

How to get the http satus value?

I'm trying to get the value of the http status Some kind of :

    export class StepsComponent implements OnInit {
        status: number;
    }

And later in a function :

    timer(){
        this.status = http.response.status;
    }

I do not want to catch the error, because I want to display something when the status is 200, so when it's OK..

Thank you for your help !

Upvotes: 0

Views: 38

Answers (1)

Kristóf Tóth
Kristóf Tóth

Reputation: 821

You might want to do something similar if you are using angularV2.

http.get(
    url,
    {observe: 'response'}
)
  .subscribe(response => {    
    // Access status:
    console.log(response.status);    
    // Access header:
    console.log(response.headers.get('Header-Name-To-Look-At'));
  });

Upvotes: 1

Related Questions