I'm trying to get users data by the link given in getsUserUrl
.To do that
it requires a token
(see the token
variable) that I have added in the header. .Whenever I start the server I get an error like this.
Can't resolve all parameters for UserServiceService: (?).at syntaxError (compiler.js:1021)
Here is my code. I don't know what parameter am I missing in Header.
import { Injectable,Pipe } from '@angular/core';
import { HttpHeaders, HttpClient ,HttpErrorResponse,HttpClientModule}
from "@angular/common/http";
import { catchError } from 'rxjs/operators';
import { throwError } from 'rxjs';
import 'rxjs/add/operator/map';
import { Token } from '@angular/compiler';
@Injectable({
providedIn: 'root'
})
export class UserServiceService {
usersData: any[] = [];
user:string
getUserUrl="https://auth.openshift.io/api/search/users?q=rohit";
token=`eysdsfdp.whsofd23.fdiu`;
constructor(private httpclient:HttpClient) {
}
private handleError(err: HttpErrorResponse | any) {
console.error('An error occurred', err);
return throwError(err.message || err);
}
searchUsers()
{
const httpOptions = {
headers: new HttpHeaders({
'Content-Type': 'application/json',
'Authorization': `Bearer ${this.token}`
})
};
var res=this.httpclient.get(this.getUserUrl,httpOptions);
return res.pipe(catchError(this.handleError));
}
}
Please let me know what am I doing wrong.
I'm attaching the code photo for your reference
As the person wanted my component code, I'm adding that too here
You need to place authorization
keyword in quotes as well
const httpOptions = new HttpHeaders({
'Content-Type': 'application/json',
'Authorization': `Bearer ${this.token}`
});
Or you can define it this way also
let httpOptions = new HttpHeaders();
httpOptions = httpOptions .set('h1', 'v1').set('h2','v2');