JSON REST
"lsProduct": [
{
"id": "p1",
"precio": "100",
"nombre": "Producto 1"
},
{
"id": "p2",
"precio": "200",
"nombre": "Producto 2"
},
{
"id": "p3",
"precio": "300",
"nombre": "Producto 3"
},
{
"id": "p4",
"precio": "400",
"nombre": "Producto 4"
}
]
HTML View
<tr ng-repeat="rsProduct in lsProduct">
<td>Nombre: {{rsProduct.nombre}}</td>
<td>Precio: {{rsProduct.precio}}</td>
<td>
<label class="check" id="{{rsProduct.id}}">
<input type="checkbox" name="" ng-model="actionProduct" ng-click="agregarCanasta(actionProduct, rsProduct)" />
</label>
</td>
</tr>
Angular Controller
$scope.lsCanasta = []; //declararlo al inicio del controller
$scope.agregarCanasta = function(actionProduct, rsProduct){
var id_product = rsProduct.id;
if(actionProduct == true){
console.log("agregando ... " + id_product);
$scope.lsCanasta.push(id_product);
$("#"+id_product).addClass("checked");
}else{
console.log("retirando ... " + id_product);
$scope.lsCanasta.splice($scope.lsCanasta.indexOf(rsProduct), 1);
$("#"+id_product).removeClass("checked");
}
}