如何在angular6中获取所选单选按钮id
我有一套单选按钮。我需要在单击后获取每个单选按钮的id,如何在ts文件中获取单选按钮id。。请帮帮我如何在angular6中获取所选单选按钮id,angular,Angular,我有一套单选按钮。我需要在单击后获取每个单选按钮的id,如何在ts文件中获取单选按钮id。。请帮帮我 <input name="r1" #tradio1 id="r1" class="custom-control-input" type="radio" [value]="0" (change)="Change($event, tradio1)"> <label class="custom-control-label" for="r1">Radi
<input name="r1" #tradio1 id="r1" class="custom-control-input" type="radio" [value]="0" (change)="Change($event, tradio1)">
<label class="custom-control-label" for="r1">Radio1</label>
无线电1
您可以为此使用ngModel指令
<input name="r1" #tradio1 id="r1" class="custom-control-input" type="radio" [value]="0" [(ngModel)]="yourvariablename" (change)="Change($event, tradio1)">
<label class="custom-control-label" for="r1">Radio1</label>
无线电1
您可以为此使用ngModel指令
<input name="r1" #tradio1 id="r1" class="custom-control-input" type="radio" [value]="0" [(ngModel)]="yourvariablename" (change)="Change($event, tradio1)">
<label class="custom-control-label" for="r1">Radio1</label>
无线电1
试着这样做:
.html
试着这样做:
.html
您可以使用与单选按钮id相同的Querylist和loop
@ViewChildren('tradio') tradio: QueryList<any>;
@ViewChildren('tradio')tradio:QueryList;
您可以使用与单选按钮id相同的Querylist和loop
@ViewChildren('tradio') tradio: QueryList<any>;
@ViewChildren('tradio')tradio:QueryList;
哦,您可以使用更改功能
Change(event, id) {
console.log(event.target.id)
}
哦,你的改变功能你可以用这个
Change(event, id) {
console.log(event.target.id)
}
你为什么不在Change()函数中以字符串参数的形式传递id?是的..我得到..谢谢你为什么不在Change()函数中以字符串参数的形式传递id?是的..我得到..谢谢你..我得到了..还有一件事,这里不需要传递id..我们只在事件中获得'id'。这是event.target.id.谢谢…我知道了…还有一件事,这里不需要传递id。我们只会在event内获取“id”。这就是event.target.id。