I have a component that calls a service. The service makes a http call. On receiving a response I want to call a function in the component from the service. How can it be done?
This is my component
import { ExportService } from '../menu/export.service';
export class Component {
constructor(public exportService: ExportService) {
}
functionToCallFromService(){
}
export(){
this.exportService.export()
}
}
Here is my Service, which makes an HTTP Post call. downloadFile() is just a function in the service that gets called once the response is received. Is there any way I can call the functionToCallFromService() of the component, once the response is received
Service is as follows
@Injectable()
export class ExportService {
export() {
this._http.post(urlToMakePostCall, formData, { responseType: 'blob'
}).retry(3)
.subscribe(response => { this.downloadFile(response,
filename)},
error => { throw new Error(error); });
}