Ionic-v1 [ I want to choose only 1 checkbox]


#1
<ion-checkbox ng-model="choice1"><b>I have extra points (+10)</ion-checkbox>
  <ion-checkbox ng-model="choice2"><b>I do not have any extra points.</ion-checkbox>

Here’s my codes. I want to choose only one checkbox in my app. How can I do that? (I’m new)


#2

or use a radio group: https://ionicframework.com/docs/components/#radio

or you could use a custom validator: http://masteringionic.com/blog/2017-01-28-validating-multiple-checkboxes-with-ionic/


#3

It could be something like that, I hope it helps you.
HTML:

<ion-checkbox ng-repeat="item in listCheckbox"
           ng-model="checkItems[item.text]" ng-change="itemShow(item.id,item.text)">
           {{ item.text }}
  </ion-checkbox>

JS:

$scope.listCheckbox = [
    {id:1,text: 'I have extra points (+10)'},
    {id:2,text: 'I do not have any extra points.'},
   
];
$scope.checkItems = { };

$scope.itemShow = function(item,text){
console.log(item);
console.log(text);
  }

Use ng-repeat, to add several checkboxes and get your position of each one.
You only need to know when the checkbox is disabled


#4

@Dann01 thank you but when I used these codes my checkboxes don’t seem in my app