I'm stuck with Angular2, I would like to pass parameters from a Products page (eg: product ids) to a Payment page, here is what I tried so far:
payment.html :
Message: {{message}}
<page-products></page-products>
payment.ts :
import { Component, ViewChild, AfterViewInit} from '@angular/core';
import { ProductsPage } from "../../products/products";
@IonicPage()
@Component({
selector: 'page-payment',
templateUrl: 'payment.html'
})
export class PaymentPage implements AfterViewInit {
@ViewChild(ProductsPage) child;
constructor(public navCtrl: NavController) {}
message:string;
ngAfterViewInit() {
this.message = this.child.message
}
}
products.ts :
import { Component} from '@angular/core';
import { IonicPage, NavController } from 'ionic-angular';
@IonicPage()
@Component({
selector: 'page-products',
templateUrl: 'products.html',
})
export class ProductsPage {
message: string = "Hola Mundo!"
constructor(public navCtrl: NavController) {}
goToPayment() {
this.navCtrl.setRoot('PaymentPage');
}
}
product.html :
<button ion-button (click)="goToPayment()">pay</button>
but I always get this error message:
Any idea of what I'm doing wrong?
here is my payment.module.ts:
import { NgModule } from '@angular/core';
import { IonicPageModule } from 'ionic-angular';
import { ComponentsModule } from '../../../components/components.module';
import { PaymentPage } from './payment';
import { ProductsPage } from '../../products/products';
@NgModule({
declarations: [
PaymentPage, ProductsPage <-- if I add here ProductsPage, then new error (see under)
],
imports: [
IonicPageModule.forChild(PaymentPage),
ComponentsModule
]
})
export class PaymentPageModule {}
and products.module.ts :
import { NgModule } from '@angular/core';
import { IonicPageModule } from 'ionic-angular';
import { ProductsPage } from './products';
import { ComponentsModule } from '../../components/components.module';
@NgModule({
declarations: [
ProductsPage
],
imports: [
IonicPageModule.forChild(ProductsPage),
ComponentsModule
]
})
export class ProductsPageModule {}
and if I declare ProductsPage like above then I get this error message:



ProductsPagecomponent to the same module thePaymentPagecomponent is associated with. Or if they are in separate modules, you have to export theProductsPagecomponent from the associated module, and import this particular module to the module thePaymentPagecomponent is bound to.