简体   繁体   English

如何在angularjs中获取所选单选按钮的值?

[英]How do i Get value of selected radio button in angularjs?

i am trying to get a value of the selected radio button but it is not working. 我正在尝试获取所选单选按钮的值,但是它不起作用。

This is my code: 这是我的代码:

<input class="star star-5" id="star-5" type="radio" name="star1" ng-model="star" ng-value="'5'"/>

<label class="star star-5" for="star-5"></label>

<input class="star star-4" id="star-4" type="radio" name="star1" ng-model="star" ng-value="'4'"/>

<label class="star star-4" for="star-4"></label>

<input class="star star-3" id="star-3" type="radio" name="star1" ng-model="star" ng-value="'3'"/>

<label class="star star-3" for="star-3"></label>

<input class="star star-2" id="star-2" type="radio" name="star1" ng-model="star" ng-value="'2'"/>

<label class="star star-2" for="star-2"></label>

<input class="star star-1" id="star-1" type="radio" name="star1" ng-model="star" ng-value="'1'"/>

<label class="star star-1" for="star-1"></label>
<div>{{start}}</div>

Could you guys please help me out?I am not checking where the error is. 你们能帮我吗?我没有检查错误在哪里。 Thank you 谢谢

正确的语法如下

 <input class="star star-3" type="radio" name="response" data-ng-model="star" data-ng-value="true"  />

Its typo start remove t in these code 其错字开始删除这些代码中的t

<div>{{star}}</div> Fiddle <div>{{star}}</div> 小提琴

Here is the correct code 这是正确的代码

<div>{{star}}</div>

And here is the plunk: https://plnkr.co/edit/JAbsgMOoagjn535fh8qE?p=preview 这就是pl: https ://plnkr.co/edit/JAbsgMOoagjn535fh8qE ? p = preview

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM