Ionic 2/3 变量访问
Ionic 2/3 Variable Access
我正在使用下面的教程构建应用内购买。
https://github.com/thielCole/ionic-iap2/blob/master/src/pages/about/about.ts
我试图让 googleProductID 等于我的 GET 调用中的 googleProductID(在 'content' 数组中)
public product: any = {
name: 'Quiz',
appleProductID: '1234',
googleProductID: this.content[0]['googleProductID'],
};
我一直收到这个错误...
core.es5.js:1020 ERROR Error: Uncaught (in promise): TypeError: Cannot read property '0' of undefined
TypeError: Cannot read property '0' of undefined
GET 调用中的一切都匹配 - 我有语法错误还是无法在此处进行调用?
***** 编辑 *******
我正在将数据从一页传递到另一页。我正在使用 IonViewWillLoad 传递来自 GET 调用的内容。
ionViewWillLoad() {
this.content = this.navParams.get('content');
this.gameGear = this.navParams.get('gameGear');
}
完成工作后,请查看 Javascript 提升 here 以了解解释器如何 reading/transforming 代码。
基本上,您的变量首先被声明,被初始化,将声明移动到顶部,最后 ionViewDidLoad 被调用(示例)。
public product: any = {
name: 'Quiz',
appleProductID: '1234',
googleProductID: undefined
};
当您从 navParams 检索它时,您可以更新您的对象
ionViewWillLoad() {
this.content = this.navParams.get('content');
// Now you have the value
this.product.googleProductId = this.content[0]['googleProductID'],
this.gameGear = this.navParams.get('gameGear');
}
我正在使用下面的教程构建应用内购买。
https://github.com/thielCole/ionic-iap2/blob/master/src/pages/about/about.ts
我试图让 googleProductID 等于我的 GET 调用中的 googleProductID(在 'content' 数组中)
public product: any = {
name: 'Quiz',
appleProductID: '1234',
googleProductID: this.content[0]['googleProductID'],
};
我一直收到这个错误...
core.es5.js:1020 ERROR Error: Uncaught (in promise): TypeError: Cannot read property '0' of undefined
TypeError: Cannot read property '0' of undefined
GET 调用中的一切都匹配 - 我有语法错误还是无法在此处进行调用?
***** 编辑 *******
我正在将数据从一页传递到另一页。我正在使用 IonViewWillLoad 传递来自 GET 调用的内容。
ionViewWillLoad() {
this.content = this.navParams.get('content');
this.gameGear = this.navParams.get('gameGear');
}
完成工作后,请查看 Javascript 提升 here 以了解解释器如何 reading/transforming 代码。
基本上,您的变量首先被声明,被初始化,将声明移动到顶部,最后 ionViewDidLoad 被调用(示例)。
public product: any = {
name: 'Quiz',
appleProductID: '1234',
googleProductID: undefined
};
当您从 navParams 检索它时,您可以更新您的对象
ionViewWillLoad() {
this.content = this.navParams.get('content');
// Now you have the value
this.product.googleProductId = this.content[0]['googleProductID'],
this.gameGear = this.navParams.get('gameGear');
}