Angular 2 HTTP Get Headers

If you want to take a look, I just set up a jsbin here

The only adjustment I made was obscuring the address I’m routing to, as it’s a company api at the moment

Thanks for your help everyone :slight_smile: I’m afraid I have to go now, but you’ve definitely helped me understand the workings of angular 2 a bit better :slight_smile:

see ya

Read this https://angular.io/docs/ts/latest/guide/server-communication.html#!#headers and try this:

request(value){
    var headers = new Headers();
    headers.append('Authorization', Bearer ' + this.token);
    var options = new RequestOptions({headers: headers});
    this.http.get( this.URL + "product/" + value, options)
    .map(
      res => res.json()
    )
    .subscribe(
      data => this.product = data,
      err => this.status.error = err
    );
  }

here is my sample code for registering function

register(firstname, lastname, email, cell, zipcode, password) {
    // set the headers
    var headers:any = new Headers();
    headers.append('Content-Type', 'application/json');
    
    var payload:any = {
        firstname: firstname,
        lastname: lastname,
        email: email,
        cell: cell,
        zipcode: zipcode,
        password: password
    };
    let result = this.http.post(this.url.concat('/users'),
        JSON.stringify(payload),
        {headers: headers});
    console.log(result);
    return result;
}

Apparently It’s the 4th line:

It should be:
this.http.get( this.URL = "product/ " + value, {headers : headers}).map(...).subscribe(...)