gpt4 book ai didi

angular - 使用angular提交后如何获取所选 ionic 单选按钮的值

转载 作者:行者123 更新时间:2023-12-02 18:38:49 24 4
gpt4 key购买 nike

.html

<ion-radio-group 
*ngFor="let option of data"
(ionChange)="checkValue($event)"
[value]="item">
<ion-item>
<ion-label>{{option.optionA}}</ion-label>
<ion-radio slot="start" value="Not"></ion-radio>
</ion-item>
<ion-item>
<ion-label>{{option.optionB}}</ion-label>
<ion-radio slot="start" value="Some"></ion-radio>
</ion-item>
<ion-item>
<ion-label>{{option.optionC}}</ion-label>
<ion-radio slot="start" value="Most"></ion-radio>
</ion-item>
<ion-item>
<ion-label>{{option.optionD}}</ion-label>
<ion-radio slot="start" value="All"></ion-radio>
</ion-item>
</ion-radio-group>

<div class="evalbtn">
<button (click)="print(event)" class="nextbtn" (click)="evaluation2()">
Submit
</button>
</div>

.ts

data: any[] = [
{
"optionA":"Not at All",
"optionB":"For some of the Time",
"optionC":"For most of the Time",
"optionD":"For all of the Time",
}
];

//function to print what is inputed in the form that is declared above
checkValue(event) {
console.log(event.detail.value)
}

print(event) {
console.log(this.checkValue(event))
}

最佳答案

ion-radio-group 添加 [(ngModel)] 而不是 [value]

<ion-radio-group *ngFor="let option of data"
[(ngModel)]="selectedValue"
(ionChange)="checkValue($event)">
<!-- items -->
</ion-radio-group>

并将 selectedValue 添加到您的组件中:

selectedValue: any;

print(event) {
console.log('Selected value: ', this.selectedValue);
}

关于angular - 使用angular提交后如何获取所选 ionic 单选按钮的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68348217/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com