Como colocar meu token de Autorização no meu pedido http (GET). Este é o meu código atual:
import { Component } from '@angular/core';
import { Http } from '@angular/http';
import { HttpClientModule, HttpHeaders } from '@angular/common/http';
@Component({
selector: 'app',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
title = 'Guilherme';
url = 'https://URL.com'
token = 'b7ff1...';
constructor(http: Http) {
let stream = http.get(this.url, {
headers: new HttpHeaders().set('Authorization', this.token),
}).subscribe();
}
}
webpack: Compiled successfully. ERROR in src/app/app.component.ts(28,36): error TS2345: Argument of type 'headers: HttpHeaders;}' is not assignable to parameter of type 'RequestOptionsArgs'
Types of property 'headers' are incompatible. Type 'HttpHeaders' is not assignable to type 'Headers'. Property 'forEach' is missing in type 'HttpHeaders'.