如何在按钮单击时提交离子单选按钮值?

Posted

技术标签:

【中文标题】如何在按钮单击时提交离子单选按钮值?【英文标题】:How to submit ionic Radio button value on button click? 【发布时间】:2021-12-17 14:32:03 【问题描述】:

点击提交按钮时需要传递选中单选按钮的值

<!--Starts Location Select Popover -->
<ion-list>
  <ion-list-header>
    <h5> Select Location</h5>
  </ion-list-header>
  <ion-item *ngFor="let store of storeLocations">
    <ion-label>store?.storeName</ion-label>
    <input type="radio" slot="end" value="store" />
  </ion-item>
  <ion-button expand="block" (click)="dismissLocationSelectPopover(store)">Submit Location
  </ion-button>
</ion-list>
<!--Ends Location Select Popover -->

【问题讨论】:

在输入时使用[(ngModel)]="yourVariable"。并将yourVariable 传递给您的函数。 【参考方案1】:

[(ngModel)] 不受支持。最好改用(click)

HTML

<input type="radio" slot="end" value="storeLoc.storeName" id="storeLoc.storeName"(click)="storeSelected(storeLoc)" />

TS

  storeSelected(storeLoc) 
    this.storeSelected = storeLoc;
  

【讨论】:

以上是关于如何在按钮单击时提交离子单选按钮值?的主要内容,如果未能解决你的问题,请参考以下文章