Ivan Paredes
Ivan Paredes

Reputation: 475

how to get the value of a item checked

I want to get the value of the selected phone : "normalizedNumber". if i check the item then i want to make a console.log of the selected telefono. i can't access to the item selected on the js file

html

<div ng-repeat="item in contactos| orderBy:'displayName' | filter : consulta">
                    <ion-item class="item-stable"
                              ng-click="abrirGrupo(item)"
                              ng-class="{active: isGroupShown(item)}">
                        <i class="icon" ng-class="isGroupShown(item) ? 'ion-minus' : 'ion-plus'"></i>
                        {{::item.displayName}}
                        <label style="float:right" ng-show="muestra">elegido</label>
                    </ion-item>
                    <ion-item class="item-accordion"
                              ng-repeat="i in item.phoneNumbers"
                              ng-show="isGroupShown(item)">

                        <ion-checkbox ng-click="cambi()"
                                      ng-model="tel"
                                      class="checkbox-dark"
                                      ng-value=i.normalizedNumber>
                            telefono: {{::i.normalizedNumber}}
                        </ion-checkbox>


                    </ion-item>
                </div>

js

$scope.cambi = function () {
            $scope.muestra = !$scope.muestra;
            console.log('elegido: ' + $scope.tel);
        };

$scope.contactos = [{
                "id": "1",
                "displayName": "Kate Bell",
                "phoneNumbers": [{
                    "number": "(555) 564-8583",
                    "normalizedNumber": "(555) 564-8583",
                    "type": "MOBILE"
                }, {
                    "number": "(415) 555-3695",
                    "normalizedNumber": "(415) 555-3695",
                    "type": "OTHER"
                }]
            }, {
                "id": "2",
                "displayName": "Daniel Higgins",
                "phoneNumbers": [{
                    "number": "555-478-7672",
                    "normalizedNumber": "555-478-7672",
                    "type": "HOME"
                }, {
                    "number": "(408) 555-5270",
                    "normalizedNumber": "(408) 555-5270",
                    "type": "MOBILE"
                }, {
                    "number": "(408) 555-3514",
                    "normalizedNumber": "(408) 555-3514",
                    "type": "OTHER"
                }]
            }, {
                "id": "3",
                "displayName": "John Paul Appleseed",
                "phoneNumbers": [{
                    "number": "888-555-5512",
                    "normalizedNumber": "888-555-5512",
                    "type": "MOBILE"
                }, {
                    "number": "888-555-1212",
                    "normalizedNumber": "888-555-1212",
                    "type": "HOME"
                }]
            }];
        }

Upvotes: 0

Views: 55

Answers (1)

Mikkel
Mikkel

Reputation: 7777

Pass the value to the callback:

<ion-checkbox ng-click="cambi(i)"

and then change the method to accept the parameter

$scope.cambi = function (telefono) {
            $scope.muestra = !$scope.muestra;
            console.log('elegido: ' + telefono);
        };

Upvotes: 1

Related Questions