Passing Data between a Page and Component

I have a page and on that page and a component as below. The data on the page below is populated after navigating from another page using

(click)="navigateToPage('PageToGoTo', restaurant)"

<ion-content padding>

In the <ion-comment-component>  component code I am trying to access but it fails with error message uncaught promise **name** cannot be found. Can I access the value in this component?

hi there, first on ts file ensure you have the following:

this.navController.push(PageToGoTo, {
	param1: 'restaurant', param2: '....''

on the restaurant single ts file;

import {NavController, NavParams} from 'ionic-angular';

constructor(private navController: NavController, private navParams: NavParams) { = navParams.get('param1'); 
this.parameter2 = navParams.get('param2');}

I have a simple solution : using the local storage

first ts file


Receiving Data Component

let ReceivedData = window.localStorage.getItem("PageToGoToData"); 
let data= JSON.parse(ReceivedData );
1 Like

The problem is accessing this.parameter2 in the component. The PageToGoTo has a component where I want to access parameter2.

No, this is going to be slower and less predictable than using a service provider or NavParams.

Not directly. If you could, the entire point of components would be lost. They need to be independent of their containers. What you can do is declare an @Input property for either the name or the entire restaurant object on your comment component (which incidentally must be renamed to not start with an ion- prefix, because that is reserved for Ionic framework components), and then pass it in like any other bound property:

<app-comment-component [restaurant]="restaurant">

Have you include the component in ts file?

----- Mensagem Original -----

That actually solved a whole host of problems. Understanding how the @Input and @Output decorators help a lot. Thank you.