How to use httpClient using get method when token

2019-08-16 02:42发布

In this post I get correct answer for problem.

Now I want to use it in get method and I want to send also in header token.

I modify it like below:

 public detailsuser(): Observable<Users[]> {
        let headers = new Headers();
        headers.append('Content-Type', 'application/json');
        headers.append('X-Token', this.currentUser.token);
        return this.http.get(Api.getUrl(Api.URLS.details), { headers: headers },{ observe: 'response' })
            .pipe(map((response: HttpResponse<any>) => {
                console.log('response', response);
                return response.body.map(data => {
                    console.log(data)
                    return new Users(data);
                });
            }));
    }

In {observe: 'response'} show this error

(property) observe: string Expected 1-2 arguments, but got 3.

Have you any idea please?

solved :

public detailsuser(): Observable<Users[]> {
            let headers = new Headers();
            headers.append('Content-Type', 'application/json');
            headers.append('X-Token', this.currentUser.token);
            return this.http.get(Api.getUrl(Api.URLS.details), 
           {
            headers: new HttpHeaders({'X-Token': this.currentUser.token}),
            observe: 'response'
           })
                .pipe(map((response: HttpResponse<any>) => {
                    console.log('response', response);
                    return response.body.map(data => {
                        console.log(data)
                        return new Users(data);
                    });
                }));
        }

0条回答
登录 后发表回答