Asked By: Anonymous
I am working on an angular 5 code. I have made an API call in serviceA as
public functionA{
let url ='someURL'
let body ={some params}
return this.http.post(url, body).map((res: any) => {
const data = res;
}
}
and I am able to get the data here.
Now i need the same data in another componentB. and i subscribed to the function as follows:
this.serviceA.functionA.subscribe(data=> console.log(data));
But here in component B , I am not able to get the data. it is undefined.
Im on angular version 5.2. Could someone please let me know on what I am doing wrong.
Solution
Answered By: Anonymous
You aren’t returning anything, the map should return the result of the callback function.
I think this will solve the problem:
public functionA{
let url ='someURL'
let body ={some params}
return this.http.post(url, body).map((res: any) => {
const data = res;
return data;
}
}