The userdetail method returns the token and other info which I need in the local component and I am getting it correctly. The token however needs to be sent in someMethod as a header so I am passing the access_token when calling the method in the auth services. Now in the auth service in someMethod when calling the api I need to send it as authorization header with bearer just like we do in postman
local component
userDetail: any = null;
access_token;
constructor(private auth: AuthService, private activatedRoute: ActivatedRoute) { }
ngOnInit() {
this.activatedRoute.data.subscribe((data: any)=> {
this.elcUserDetail = data.elcUserDetailResolver.body.data;
this.access_token = this.elcUserDetail.access_token;
console.log(this.access_token);
})
if(this.userDetail != null){
this.auth.someMethod(this.access_token).subscribe((res)={
})
}
}
Auth service
headers: any;
userdetail(): Observable<any> {
return this.http.get(this.userdetailURL, {observe: 'response'});
}
someMethod(access_token) {
const headers = new Headers({ Authorization: `Bearer this.headers`});
}
return this.http.post(this.someURL, null,{headers: this.headers } );
}
user Detail resolve
export class UserDetailResolveService implements Resolve<any> {
constructor(private auth: AuthService, private http: HttpClient) { }
resolve(route: ActivatedRouteSnapshot) {
return this.auth.userdetail();
}