Hi Alex,

Two things. First, as the error tells you, you need to use HttpHeaders, not 
Headers. See here from your example:

On Tuesday, August 7, 2018 at 7:02:01 PM UTC+2, a.kr...@ich-selber.de wrote:
>
>
> import { HttpClient, HttpHeaders } from '@angular/common/http';
>         const headers = new Headers();
>
>
You import HttpHeaders from Angular, and then use Headers 
<https://developer.mozilla.org/en-US/docs/Web/API/Headers> (native to 
browsers). You could mix them, but it's safer to use Angular's classes in 
Angular environment, due to various reasons outside of the scope here.

So use const headers = new HttpHeaders(); instead.


The other problem - HttpHeaders (the class from Angular import, the one you 
actually need) is immutable. So you have to change this:  

const headers = new HttpHeaders();
headers.append('appkey', '123');

Into this:

let headers = new HttpHeaders();
headers = headers.set('appkey', '123');

// or chain them all together this way:

const headers = new HttpHeaders().set('appkey', '123').set('Content-Type', 
'application/json');

Anything you append to headers later in your code will not actually be 
added. 

Zlatko

-- 
You received this message because you are subscribed to the Google Groups 
"Angular and AngularJS discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to angular+unsubscr...@googlegroups.com.
To post to this group, send email to angular@googlegroups.com.
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to