I'm trying to get some data and return something on success using an Angular HttpClient call like this:
return this.http.post('api/my-route', model).subscribe(
data => (
this.data = data;
return $window.location = ReturnUrlService.getAbsolute('/my-other-route');
)
)
Why can't I do this? My app is Angular 4.3 with TypeScript 2.6.2 My understanding is that the arrow function should be the equivalent of this callback:
function(data) {
this.data = data;
return $window.location = ReturnUrlService.getAbsolute('/my-other-route');
}
... and I'm treating 'data' like it will work as a 'success' callback in JQuery AJAX. Is a subscribe somehow limited to setting values of of properties within the class? What's wrong with my arrow function? I know I'm missing something basic!
data => ( ... )should be replaced withdata => { ... }, (2)subscribe()returns aSubscriptioninstance (often used to call itsunsubscribemethod), not the value returned by the callback function.