Angularjs单选按钮 [英] Angularjs radio buttons
本文介绍了Angularjs单选按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道,这已经在一些谷歌的主题已经谈过,但我仍然无法找到我的电台输入绑定到一个模型中的正确的解决方案(以clean'n简单的方式),
I know that this has been spoken about in some Google Threads but I still can't find the right solution to bind my radio inputs to a model (in clean'n simple manner),
目前我有HTML:
<input ng-model="searchByRma" type="radio" name="search-type">
<input ng-model="searchByDelivery" type="radio" name="search-type">
和在控制器:
$scope.searchByRma = true;
$scope.searchByDelivery = false;
这不工作(因为它会与复选框)...
This does not work (as it would with the checkboxes)...
这是如何设置第一个单选按钮默认值的任何想法而不会丢失数据绑定?
Any ideas on how to set the default value on the first radio button without loosing data-binding?
谢谢!
推荐答案
我认为你应该使用相同的变量,在这些不同的价值观
两个单选按钮。
I think you should use same variable with different values in those two radio buttons.
<input ng-model="searchBy" value="Rma" type="radio" name="search-type">
<input ng-model="searchBy" value="Delivery" type="radio" name="search-type">
然后,你应该有搜索项
设置不是RMA或交货,这取决于
用户输入。
Then, you should have searchBy
set either "Rma" or "Delivery" depending on
user input.
这篇关于Angularjs单选按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文