I\'ve been learning TypeScript with Angular. And currently I stuck as this moment. Previously I used subscribed method and everything works flawlessly, but not I decided to
Why not directly return an Observable
from your service?
getRestaurant(): Observable {
return this.http.get(environment.api + "/restaurant")
.map((response: responseFormat) => response.data as restaurant);
}
Then on component side:
getRestaurant() {
this.restaurantProvider.getRestaurant().subscribe((res: restaurant) => {
this.restaurant = res;
});
}
The error handling (success
flag, HTTP errors, etc) could be handled via an HTTP Interceptor.