user.component.ts
ngOnInit(): void
{
var data;
this.auth=this.cookie.get("auth");
this.servicefetch.ContactList(this.auth).subscribe
(
(response)=>
{
data=response;
},
(error)=>{console.log(error)}
);
}
serviceCRUD.service.ts
ContactList(auth:String)
{
const headers = { "content-type": "application/json", "Authorization": "Contacts " + auth };
return this.http.get<any>('http://localhost:8080/contacts', {headers});
}
Here I want to assign the response to the other variable say data. But when I print out the data I get undefined. I think it is because this is asynchronous. Any way I can assign it to the variable data