[英]Radio Button and AngularJS
I know this is a common question on SO, but none of those solve my issue. 我知道这是SO的常见问题,但是没有一个解决我的问题。
This code doesn't allow me to click/select the radio button. 此代码不允许我单击/选择单选按钮。 And I am unable to see whats wrong. 而且我看不出有什么问题。 It may bey something simple that I am missing, I'll be glad if someone can help out. 可能我缺少一些简单的东西,如果有人可以帮忙,我会很高兴。
<div input-field class="col m6" ng-init="student.username = 0">
<p>Username Generation</p>
<p>
<input class="with-gap" type="radio" name="user" ng-model="student.username" value="0" required />
<label>Same as Registration ID</label>
</p>
<p>
<input class="with-gap" type="radio" name="user" ng-model="student.username" value="1" required />
<label>Auto Generate</label>
</p>
The problem is I cannot select the Radio button, where set in ng-init or not. 问题是我无法选择是否在ng-init中设置的单选按钮。
JSFIDDLE: https://jsfiddle.net/znfvmr80/5/ JSFIDDLE: https ://jsfiddle.net/znfvmr80/5/
Well the fix was relative easy, and kinda due to me missing out on a for
attribute. 好了,修复相对容易,而且由于我错过了for
属性而造成的。 Thanks to @Joyson for helping out, him thinking got me thinking. 感谢@Joyson的帮助,他的思想让我思考。
This is the correct code: 这是正确的代码:
<div input-field class="col m6" ng-init="student_username = 0">
<p>Username Generation</p>
<p>
<input class="with-gap" type="radio" name="user" ng-model="student_username" value="0" required id="same_as_reg" />
<label for="same_as_reg">Same as Registration ID</label>
</p>
<p>
<input class="with-gap" type="radio" name="user" ng-model="student_username" value="1" required id="autogen" />
<label for="autogen">Auto Generate</label>
</p>
Materialize requires a for
attribute label for radio buttons to work. Materialise 需要一个for
属性标签才能使单选按钮起作用。
Thanks everyone! 感谢大家!
您提供的代码运行良好,我认为您可以在初始化之前或之后在js中进行更多检查。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.