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文件主页.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>
当我点击一个产品时,它会在控制台日志中显示“undefined” 导入“…”声明和条目组件
在您使用的代码中 products 在 ngFor ,因此在调用方法click时应该使用该变量
products
ngFor
<ion-item *ngFor="let products of moreProducts" text-wrap (click)="openProductPage(products)">