I'm using routerLink to send an id of a component with a list of restaurants to another component through the URL
[routerLink]="['../restaurant-menu', restaurant.id]"
in the other component I use it in the following way
ngOnInit() {
this.restaurantId = this.router.snapshot.params['id']
getRestaurantMenu(this.restaurantId)
}
restaurantMenu: void[]
getRestaurantMenu(id): void {
this.RestaurantsService.getRestaurantMenu(id)
.subscribe(
restaurantMenu => this.restaurantMenu = restaurantMenu,
err => {
console.log(err);
});
}
Everything works correctly the first time I enter a restaurant, and it loads its menu, the problem is that when I return to the list of restaurants and enter a different one I am charged the menu of the first restaurant I enter, I have to refresh the page manually so that it loads the correct menu.
I do not know if the id is updated after calling the function of getRestaurantMenu () because no matter how many times I go out and enter different restaurants it will always be the menu of the first restaurant that I will also see if I do this :
<p> {{restaurantId}} </p>
The id number shown on the screen is correct. I have tried different ways to pass that id but the result is the same, what could be the problem? thanks