How to get the ion flag value

I show my list of checkboxes with this code:

 <ion-checkbox ng-repeat="item in listPref"
   ng-model="item.checked" ng-checked="item.checked">
   {{ item.text }}
 </ion-checkbox>

This is my list Pref:

 $scope.listPref = [
    {text: 'Cinema'},
    {text: 'Sport'},
    {text: 'It'} ,
    {text: 'Music'},
    {text: 'Theater'},
    {text: 'Conference'}];

I try this code to get the text of the whole selected item

 for(var i =0 ; i <$scope.listPref.length ; i++){
console.log($scope.listPref[i].checked.text); 
 } 

I get a message undefined Cannot read property 'text' of undefined at Scope.$scope.prefin my console. Can someone help me.

+4
source share
1 answer

HTML:

<ion-content>
   <ion-checkbox ng-repeat="item in listPref"
       ng-model="checkItems[item.text]" ng-change="print()">
       {{ item.text }}
   </ion-checkbox>
   <button type="button" name="button" ng-click="save()">Save</button>
</ion-content>

JS (internal controller):

$scope.listPref = [
    {text: 'Cinema'},
    {text: 'Sport'},
    {text: 'It'} ,
    {text: 'Music'},
    {text: 'Theater'},
    {text: 'Conference'}
];

$scope.checkItems = { }

$scope.print = function() {
    console.log($scope.checkItems);
}

$scope.save = function() {
    var array = [];
    for(i in $scope.checkItems) {
        console.log($scope.checkItems[i]);
        if($scope.checkItems[i] == true) {
            array.push(i);
        }
    }
    console.log(array);
}

, , . print() , (true/false). save() . , , , , , , .

, .

+5

All Articles