I'm a beginner in the world of Ionic and I've encountered an issue with my code. In my restaurant.html page, I have a list of restaurants that, when clicked, should display the full details on another page. However, it seems that the details for each restaurant are not being passed correctly. Can anyone help me figure out where I've gone wrong?
Here is the code:
restaurant.html
<ion-header>
<ion-navbar color="restaurant-color">
<button ion-button menuToggle>
<ion-icon name="menu"></ion-icon>
</button>
<ion-title>Restaurants</ion-title>
</ion-navbar>
</ion-header>
<ion-content padding class="restaurants attractions common-bg">
<div class="card round" margin-bottom *ngFor="let restaurant of restaurants" (click)="viewRestaurant(restaurant.id)">
<div class="card-header" [ngStyle]="{'background-image': 'url(' + restaurant.thumb + ')'}"></div>
<div class="padding-xs">
<h5>{{ restaurant.name }}</h5>
<div class="rating">
<ion-icon name="md-star" color="restaurant-color" *ngFor="let star of range(restaurant.rating)"></ion-icon>
<ion-icon name="md-star" color="gray" *ngFor="let star of range(5 - restaurant.rating)"></ion-icon>
<span color="gray">{{ restaurant.reviews.length }} reviews</span>
</div>
<span color="gray">Recommended for:</span>
<div>
<div class="pull-left">
<span color="restaurant-color">{{ restaurant.scores[0].name }},</span>
<span color="restaurant-color">{{ restaurant.scores[1].name }}</span>
</div>
<div class="pull-right">
{{ restaurant.location.distance }} km
</div>
<div class="clear"></div>
</div>
</div>
</div>
</ion-content>
and for restaurants.ts
import {Component} from "@angular/core";
import {NavController} from "ionic-angular";
import {RestaurantService} from "../../services/restaurant-service";
import {RestaurantDetailPage} from "../restaurant-detail/restaurant-detail";
@Component({
selector: 'page-restaurants',
templateUrl: 'restaurants.html'
})
export class RestaurantsPage {
// list of restaurants
public restaurants;
constructor(public nav: NavController, public restaurantService: RestaurantService) {
this.restaurants = restaurantService.getAll();
}
// view restaurant detail
viewRestaurant(id) {
this.nav.push(RestaurantDetailPage, {id: id})
}
// make array with range is n
range(n) {
return new Array(Math.round(n));
}
}