如果我在字段中为属性分配值,而不是在打字稿中的构造函数中为字段中的proda = this.navParams.data;
分配值,则可以正常工作。我尝试了这一点,似乎可以在我的离子页面.ts文件中使用它了。
这是下面正确的原始代码:
import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
/**
* Generated class for the BuyoutPage page.
*
* See https://ionicframework.com/docs/components/#navigation for more info on
* Ionic pages and navigation.
*/
@IonicPage()
@Component({
selector: 'page-buyout',
templateUrl: 'buyout.html',
})
export class BuyoutPage {
proda;
constructor(public navCtrl: NavController, public navParams: NavParams) {
this.proda = this.navParams.data;
}
ionViewDidLoad() {
console.log('ionViewDidLoad BuyoutPage');
}
onConfirm(){
this.navCtrl.popToRoot();
}
}
这是我尝试将值分配给字段但不在构造函数中的代码,并且似乎可以正常工作:
import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
/**
* Generated class for the BuyoutPage page.
*
* See https://ionicframework.com/docs/components/#navigation for more info on
* Ionic pages and navigation.
*/
@IonicPage()
@Component({
selector: 'page-buyout',
templateUrl: 'buyout.html',
})
export class BuyoutPage {
proda = this.navParams.data;
constructor(public navCtrl: NavController, public navParams: NavParams) {
}
ionViewDidLoad() {
console.log('ionViewDidLoad BuyoutPage');
}
onConfirm(){
this.navCtrl.popToRoot();
}
}