Search code examples
angularjschecklist-model

I am trying to make checkbox act like radio button with angularjs


I am trying to make checkbox work like radio button. When one checkbox is checked another checkbox should automatically uncheck.

Can anyone show me how to do it.

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>

Solution

  • // HTML in INPUT
    ng-true-value="{{role.id}}" ng-false-value=""  ng-model="result.id"
    // Controller 
    $scope.result = {};
    

    You can check $index like that

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

    its working :)