I've been banging my head on this for the better part of a week and I'm finally issuing a call to the StackOverflow universe in hopes someone has encountered this issue before and can help me figure it out.
I am new to Angular2 and this is my first app with it. I am just trying to wire up to an api call to get a list of businesses. I have a search input field on a component that makes a call within a service. The call is continuously failing because I can't seem to pass the headers to the call with the proper authentication from the session token that I have. It always passes just with {"content-type": "application/json"}.
Here is the call on my service:
searchAllForTerm(term: string): Promise<Business[]> {
let headers = new Headers();
headers.append('Content-Type', 'application/json');
let authToken = localStorage.getItem('token');
headers.append('Authorization', `Bearer ${authToken}`);
return this.http.get(this.businessesUrl + term, {headers})
.toPromise()
.then(this.extractData)
.catch(this.handleError);
}
I have imported
import { Http, Response, Headers} from '@angular/http';
on the file and set the constructor to
constructor(private http: Http) {}
Still, when the call gets made the authorization is not in the header. Any ideas?