Why not directly return an Observable<restaurant>
from your service?
getRestaurant(): Observable<restaurant> {
return this.http.get<responseFormat>(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.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…