Can't seem to wrap my head around chaining / wrapping observables. I am using Angular2 rc1 with RxJs in Typescript in Visual Studio 2015.
I have a servicemethod 'saveProduct' in the ProductService class:
public saveProduct(product: Product): Observable<string> {
let options = new RequestOptions({ headers: new Headers({ 'Content-Type': 'application/json' }) });
return this.http.post(this.config.apiUrl + '/product', JSON.stringify(product), options).map(this.extractData).catch(this.handleError);
}
I consume it in an angular2 component:
public save() {
this.productService.saveProduct(this.product).subscribe(
result => this.productSaveExecuted(result),
error => this.handleError(error)
);
}
The component is wrapped in a modal dialog wiIf I would close the dialog after calling the component's save method, the dialog would be closed before the save action is finished. So, figure I want the component's save function to also return an Observable, because the component is wrapped in a modal div witch I want to close after a successful save. How do I accomplish this?