Search code examples
angularhttpstatus

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 !


Solution

  • 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'));
      });