replace object value in angularjs

1

Hello, I need to use the id I send from the view, the code of the switch is this:

       <div ng-repeat="model in modelo_final">
         <div style="float:left; padding-right:100px;">
         <div class="can-toggle demo-rebrand-2">
         <input  id={{model.id}} type="checkbox" ng-model="idrecibo[model.id]" ng-change="changeItem()">
          <label for={{model.id}}>
           <div class="can-toggle__switch" data-checked="Yes" data-unchecked="No"></div>
           <div class="can-toggle__label-text"><p style="font-size:15px; width:100px;">{{model.nombre}}</p></div>
           </label>
           </div>
         </div>
       </div>

which when being dynamic I send model.id that corresponds to its id respective, this I want to use it in the controller to be able to activate and deactivate the switch $scope.idrecibo = {};

Pressing the switch (activate) sends your id . by console, and it would look something like this:

And if I activate another button:

which I would like it to be replaced, so always have one (the last one you activate) and that power to use it to tell my web services to activate the module or deactivate.

and another question, how can I get the true false from there? What is left only the number or how should I use it to send just the number?

Thank you.

    
asked by Hernan Humaña 20.12.2016 в 20:52
source

1 answer

1

idRecibo is an array that by index has the id of the module and by value true or false depending on the switch simply to get the value you send when the switch changes is:

ng-change="changeItem(model.id)"

This function should receive as parameter the data model.id

$scope.changeItem = function(id_model){
     console.log($scope.idrecibo[id_model]);
}

That will give you the value true or false of the switch that you changed and not all.

To the web service, you should always send the $scope.idrecibo[id_model] per parameter.

    
answered by 20.12.2016 / 21:16
source