How to get the value from ion-select option

前端 未结 3 1025
借酒劲吻你
借酒劲吻你 2020-12-31 05:35

I have an array of object called options.

this is my html code

    
        place         


        
3条回答
  •  忘掉有多难
    2020-12-31 06:16

    There were several things that together caused that error. The first change there is that instead of using the click event like this:

    (click)="optionsFn(item);
    

    You should use the ionChange event that Ionic exposes like this:

    (ionChange)="optionsFn();"
    

    Also notice that since you use the [(ngModel)]="place" to bind the select element to one of your component's properties, you don't need to send the item as a parameter, because this.place will be the selected item when the ionChange event is triggered.

    That's why your optionsFn method would look like this:

    public optionsFn(): void { //here item is an object 
        console.log(this.place);
    
        let item = this.place; // Just did this in order to avoid changing the next lines of code :P
    
        this.product_option_value_idOp = item.product_option_value_id;
        this.priceOp = item.price;
        this.salespriceOp = item.salesprice;
        this.quantityOp = item.quantity;
        this.skuOp = item.sku;
        this.nameOp = item.name;
      }
    

提交回复
热议问题