Angularjs 单选按钮 [英] Angularjs radio buttons

查看:33
本文介绍了Angularjs 单选按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道在一些 Google Threads 中已经谈到了这一点,但我仍然找不到将我的无线电输入绑定到模型的正确解决方案(以简洁的方式),

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">

然后,您应该让 searchBy 设置Rma"或Delivery",具体取决于用户输入.

Then, you should have searchBy set either "Rma" or "Delivery" depending on user input.

这篇关于Angularjs 单选按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆