How get checked value from radio button angular

早过忘川 提交于 2019-12-06 03:28:01

You can bind the data of radio button. Just add the value for radio button and change in the ngModel

html

<input class="form-check-input" type="radio" value="dog" 
[(ngModel)]="dog.value" name="gob" value="i" [checked]="true" 
(change)="onItemChange($event)"/>

ts

onItemChange(value){
   console.log(" Value is : ", value );
}

The data binding of radiobuttons is dependent of the value attribute. So if you set your variable dog equels the string "dog" the first radiobutton will be selected.

To get the value of the radiobutton on click you can either pass the string directly in your onItemChange event or access it via the event variable:

https://stackblitz.com/edit/angular-csusjt?file=src%2Fapp%2Fapp.component.html

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!