I currently have 2 components and 1 service file. The **Component** is where I need the response to be displayed. My goal is to call a function from the Master component in Component 1 and receive the response back in the Master component.
My concern lies in figuring out how to pass the same API response from the Master component to Component 1 using async/await. Any assistance would be greatly appreciated!
Component.ts
async fetchData() {
const result = await this.Mastercomponent.getData();
console.log(result, ": result of function");
Mastercomponent.ts
async getData() {
this.service.fetchData(object).subscribe(
data => {
console.log(data, "Received Response in Mastercomponent");
return data;
}
);
}
Service.ts
return this.http.post(parameters, { headers: header, responseType: 'text' }).pipe(
tap(data => {
console.log(data, "Received Response in Service");
}),
catchError(this.handleError)
);