0
This below is a brief explanation.
By clicking the register on browser screen I can not load the records according to the ID.
This below is a detailed application;
View the gif file
You can notice that there are two records being loaded and by clicking on the records it is able to load in the URL the registration ID, when viewing the console you notice that it lists the database records that are only two same.
The problem is that when placing on the page {{ restaurant?.name }}
it does not print on the screen the value of the bank.
I don’t know what I’m doing wrong, this is my kind of services;
restaurantById(id: string): Observable<Restaurant> {
return this.http.get(`${this.url}/restaurants/${name}`)
.map(response => response.json().restaurants)
.catch(ErrorHandler.handlerError)
}
This is my component class according to web page.
ngOnInit() {
this.restaurantService.restaurantById(this.route.snapshot.params['id'])
.subscribe(restaurant => this.restaurant = restaurant)
}
sorry I put it in high box, because sometimes people do not realize that I have put the link from my repository.
The page is inside the package Restaurant-Detail and the service is the archive Restaurant.service.ts
I’ll be waiting for a comeback, I really need help.
SERVER RESPONSE
Shouldn’t be
${id}
here??this.http.get(
${this.url}/Restaurants/${name}`– Leonardo Lima
If I put the as you are suggesting it does not load the bank records in the component class
– wladyband
But then you have to see the return of the API tbm, and adjust as needed... What is happening is that you are probably getting an array of restaurants (see
response.json().restaurants
), but tries to display only one.– Leonardo Lima
In your class of service where you have
.map(response => response.json().restaurants)
shouldn’t be?.map(response => response.json())
– Marconi
@Marconi I tried your suggestion, but did not catch, still not appearing the records on screen.
– wladyband
@wladyband you started json-server?
– Marconi
Try it this way:
restaurantById(id: string): Observable<Restaurant> {
 return this.http.get(
${this.url}/Restaurants/${id})
 .map(response => response.json())
 .catch(ErrorHandler.handlerError)
}– Marconi