我的产品页面中的未定义对象

时间:2018-08-29 18:09:31

标签: javascript angular typescript ionic3

这是我到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>

当我单击产品时,它在控制台日志中显示“ undefined” 顺便说一句,我在app.module.ts中添加了所有必要的东西 导入“ ...”,声明和entryComponents

1 个答案:

答案 0 :(得分:2)

在您的代码中,您正在products中使用ngFor,因此在调用click方法时应使用该变量

<ion-item *ngFor="let products of moreProducts" text-wrap (click)="openProductPage(products)">