Hello, everyone presented a new challenge and I need help from you, it turns out that I need to send a data to the controller to use it:
<div ng-repeat="model in modulos track by $index">
<div style="float:left; padding-right:100px;">
<div class="can-toggle demo-rebrand-2">
<input id="{{ id[$index] }}" type="checkbox" ng-model="ValueModulo">
<label for="{{ id[$index] }}">
<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}}</p></div>
</label>
</div>
</div>
</div>
ok within the div
, there is a ng-repeat
that shows switches according to the number that exist (varies) and is accompanied by an id which by track by $index
I assign it to its respective module, now I want to send this id to the controller, especially only one, that is when you activate the switch to be able to use it there ...
How can I send it?
in the controller I am using the following code to make the changes:
Conection.CheckModulo({
modulo_id: IDRECIBIDO
}, function(respuesta) {
var data = JSON.parse(JSON.stringify(respuesta));
var activo = data.activo;
if(activo === "1"){
$scope.ValueModulo = true;
}
else if(activo === "0"){
$scope.ValueModulo = false;
}
else {
console.log('Error de respuesta');
}
});
$scope.$watch('ValueModulo', function(val) {
if (!angular.isUndefined(val)) {
if (val) {
Conection.OnPreferencial({
modulo_id: IDRECIBIDO
});
} else {
Conection.OffPreferencial({
modulo_id: IDRECIBIDO
});
}
}
});
'
Here I ask about the status of the switch, and depending on that it is shown on or off,
and with the $ scope.watch active or deactivate the switch