我被 Angular2 困住了,我想从 a 传递参数产品页面(例如:产品 ID)到支付页面,这是我迄今为止尝试过的:
付款.html:
Message: {{message}}
<page-products></page-products>
付款.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
}
}
产品.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');
}
}
产品.html:
<button ion-button (click)="goToPayment()">pay</button>
但我总是收到此错误消息:
知道我做错了什么吗?
这是我的 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 {}
和 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 {}
如果我像上面那样声明 ProductsPage ,那么我会收到以下错误消息: