这是我在 product-details.ts 中的构造函数
product: any;
constructor(public navCtrl: NavController, public navParams: NavParams) {
this.product = this.navParams.get("product");
console.log(this.product);
}
这是我的家.ts
openProductPage(product){
this.navCtrl.push(ProductDetailsPage, {"product": product} );
}
这是 html 文件 home.html
<ion-list>
<ion-item *ngFor="let products of moreProducts" text-wrap (click)="openProductPage(product)">
<ion-thumbnail item-left>
<img [src]="products.featured_src" />
</ion-thumbnail>
<h1>{{products.title}}</h1>
<p>
<span [innerHTML]="products.short_description.substr(0, 50) + '...'"></span>
<span [innerHTML]="products.price_html"></span>
</p>
<button ion-button icon clear item-right>
<ion-icon name="arrow-forward"></ion-icon>
</button>
</ion-item>
</ion-list>
当我点击一个产品时,它在控制台日志中显示“未定义” 顺便说一下,我在 app.module.ts 中添加了所有必要的东西 其中导入“...” & 声明 & entryComponents
最佳答案
在您的代码中,您在 ngFor
中使用了 products
,因此您应该在调用方法 click 时使用该变量
<ion-item *ngFor="let products of moreProducts" text-wrap (click)="openProductPage(products)">
关于javascript - 我的产品页面中的 undefined object ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52083744/