【发布时间】:2018-08-29 18:09:31
【问题描述】:
这是我在 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 中添加了所有必要的东西 其中 import "..." & 声明 & entryComponents
【问题讨论】:
-
您在 (click) 方法中传递了错误的变量。那应该像 (click)="openProductPage(products)"
标签: javascript angular typescript ionic3