Hi @all,

I´m very new to Angular CLI an Programming. I hope for  some help on this 
Problem.

I have this Code


import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { map } from 'rxjs/operators';

import { environment } from '../../environments/environment';

@Injectable()
export class AuthenticationService {
    constructor(private http: HttpClient) { }

    login(username: string, password: string) {
        const headers = new Headers();
headers.append('Content-Type','application/json');
headers.append('appkey','123');


        return this.http.post<any>(`${environment.apiUrl}/login`, { user: 
username, pass: password }, { headers: headers})
        
            .pipe(map(data => {
                // login successful if there's a jwt token in the response
                if (data && data.sessionID) {
                    // store user details and jwt token in local storage to 
keep user logged in between page refreshes
                    localStorage.setItem('currentUser', JSON.stringify(data
));
                }

                return data;
            }));
    }

    logout() {
        // remove user from local storage to log user out
        localStorage.removeItem('data');

    }
}


What I try is to set Headers (e.g. 'appkey':'123') but I get this error:

> Argument of type '{ headers: Headers; }' is not assignable to parameter of 
> type '{ headers?: HttpHeaders | { [header: string]: string | string[]; }; 
> observe?: "body"; params?: Ht...'.
>   Types of property 'headers' are incompatible.
>     Type 'Headers' is not assignable to type 'HttpHeaders | { [header: 
> string]: string | string[]; }'.
>       Type 'Headers' is not assignable to type '{ [header: string]: string 
> | string[]; }'.
>         Index signature is missing in type 'Headers'.
>

How to solve this?

Thanks for ur Help

Greetings from Germany

Alex

-- 
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to