0

Well, the question's pretty self-explanatory.

The thing is, this is an already developed project and, for reasons beyond my understanding, they want a radio button functionality for certain checkboxes. Why? Can't explain it and also can't change it.

Is there a way to achieve this behavior? Thanks in advance.

1 Answer 1

1

are you looking for something like this: basically you have handle the click of checkbox and mark others as not selected, you can achieve this by playing with the model value here.

sample:

JS:

app.controller('MainCtrl', function($scope) {
  $scope.chkList = [{
    name: "Ram",
    isSelected: false
  }, {
    name: "Shyam",
    isSelected: false
  }, {
    name: "Alice",
    isSelected: false
  }, {
    name: "Adam",
    isSelected: false
  }];

  $scope.deSelectOther = function(item) {
    $scope.chkList.forEach(function(listItem) {
      if (listItem.name != item.name)
        listItem.isSelected = false;
    })
  }
});

HTML:

 <li ng-repeat="item in chkList">
    <span>{{item.name}}</span>
    <input type="checkbox" ng-click="deSelectOther(item)" ng-model="item.isSelected" />
 </li>

plunkr here

if no? post some of your code or further elaborate your requirement so that I can help you

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.