0

I'm fairly new to angular 2 and am trying to make an http request with headers.

I've been following a tutorial, that may be out of date, as I'm getting an error when trying to include Headers.

I'm importing the Headers module:

import { Http, Headers } from '@angular/http';

Here is my method, where I try to include the headers:

  memberInfo(){
    let headers = new Headers().set('Authorization', this.authToken);
    this.http.get(this.API_ENDPOINT + '/memberinfo', { headers });
  }

I get the following error:

[ts]
Argument of type '{ headers: void; }' is not assignable to parameter of type 'RequestOptionsArgs'.
  Types of property 'headers' are incompatible.
    Type 'void' is not assignable to type 'Headers'.

Any insight would be great!!

1
  • Try changing { headers } to { headers: headers }. Commented Feb 15, 2018 at 2:16

3 Answers 3

1

Try this :

let header = new Headers();
header.append(´Authorization´, this.authToken);
this.http.get(this.API_ENDPOINT + ´/memberinfo´, {headers: header})
Sign up to request clarification or add additional context in comments.

Comments

1

You need to assign to headers

 this.http.get(this.API_ENDPOINT + '/memberinfo', { headers: headers });

Comments

0
let headers = new Headers({ 'Content-Type': 'application/json' },{'Authorization'´: this.authToken});
this.http.get(this.API_ENDPOINT + ´/memberinfo´, {headers: header})

if you're expecting some response then:

this.http.get(this.API_ENDPOINT + ´/memberinfo´, {headers: header}).map(response => response.json());

Here I am converting GET request response and converting it to JSON.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.