【问题标题】:I am trying to make checkbox act like radio button with angularjs我正在尝试使复选框像带有 angularjs 的单选按钮一样
【发布时间】:2023-03-18 20:49:02
【问题描述】:

我正在尝试使复选框像单选按钮一样工作。 当一个复选框被选中时,另一个复选框应该自动取消选中。

谁能告诉我怎么做。

Example

<label ng-repeat="role in roles">
    <input id="{{role.text}}" type="checkbox" onbeforesave="validateRequired($data)" 
           ng-click="$last&&mytest(checked)" ng-disabled="user.text"  
           checklist-model="user.roles" checklist-value="role.text" 
           ng-init="user.roles=false"/>
               {{role.text}} &nbsp;&nbsp;
</label>

【问题讨论】:

  • 不能只使用单选按钮吗?
  • 没有问题:(
  • 将复选框更改为单选按钮的用例是什么

标签: angularjs checklist-model


【解决方案1】:
// HTML in INPUT
ng-true-value="{{role.id}}" ng-false-value=""  ng-model="result.id"
// Controller 
$scope.result = {};

你可以这样检查 $index

     $scope.check = function (index) {
                $scope.type = index;        
            }
    $scope.type === $scope.result.id
>>>>> true

它的工作:)

【讨论】:

  • 感谢@Mike86 在 html 行中使用 checklist-model="user.roles" 而不是 ng-model="" 的回复。它可以与清单模型一起使用吗?
  • 它没有区别,只需将我的代码添加到输入和控制器并尝试它的工作:) 请接受有用兄弟的回答
  • 它现在正在工作@Mike86,你能在我附加的 plunker 中显示它吗?兄弟,我绝对会接受你的回答。
  • plnkr.co/edit/5qG1O1opTjGCS6lByf6R?p=preview 它的工作你的代码人请投票
猜你喜欢
  • 2011-06-09
  • 1970-01-01
  • 2013-02-09
  • 2012-12-09
  • 1970-01-01
  • 2013-10-23
  • 2016-03-20
  • 2017-01-07
  • 2015-12-09
相关资源
最近更新 更多