Angular2:
I have a component and a service. Component calls service and it must return the response. The problem is that I don't know how to return the response. My component is like:
uploadFile(docId: any) {
let pos = this.uploader.queue.length-1;
//We pick the last one
this._uplService.uploadDoc(this.uploader.queue[pos], docId, this.innerText)
}
The service does this thing:
uploadDoc(file: FileItem, docId : any, title: String){
let headers = this._httpWrapper.genetareAuthHeader("path", "POST");
let user = this._userService.getUser();
file.url = user.config.apiUrl+"path?options="+user.options;
file.upload();
file.onSuccess = function(response: string, status: number, headers: ParsedResponseHeaders) {
console.log(response);
}
file.onError = function(response: string, status: number, headers: ParsedResponseHeaders) {
console.error(response);
}
My problem is to return response and error from the service to the component. I tried to do an observable from promise, from response etc. but observables are really hard and all the times I tried, 'uploadDoc' returned a function (file.onSuccess or file.onError) not the value returned by the function (response).