Im using angularjs to show a table from a json records with checkbox, and i have two problems:
First: I need all checkboxs true by default. Tested with ng-init but not working. Or just a button to toggle true-false all checkboxs
Second When uncheck a file, the object show quotes["", "", ""], but i need to show anything if not checked
view
<div ng-controller="TestController">
<table class="table table-striped">
<tr>
<th>Seleccionar</th>
<th>Servicio</th>
<th>Detalle</th>
<th>Precio</th>
</tr>
<tr ng-repeat="(key, value) in listado">
<td><input type="checkbox" ng-model="ids[$index]" ng-true-value="{{value}}" ng-false-value="{{ undefined }}" ng-selected="checkAll"></td>
<td>{{ value.modelo }}</td>
<td>{{ value.detalle }}</td>
<td>{{ value.precio_in | currency:'$':0 }}</td>
</tr>
</table>
{{ ids | json }}
controller
var myApp = angular.module('myApp', [])
.controller('TestController', ['$scope', function ($scope) {
$scope.listado = [];
$scope.ids = [];
$scope.listado = [ { "id_stock": "4", "oc_id": "4", "detalle": "Revisión de suspención", "cat_id": "16", "codigo": "m20.1", "marca": "", "parte": "", "precio_in": "5000", "id_prov": "1", "cantidad": "1", "id_bodega": "1", "nom_prov": "Proveedor de prueba 1", "modelo": "MECANIZADOS Y OTROS", "nombre": "Bodega Conchalí", "status": "EN BODEGA", "id_cat": "16" }, { "id_stock": "5", "oc_id": "4", "detalle": "Revisión de frenos", "cat_id": "16", "codigo": "m2.2", "marca": "", "parte": "", "precio_in": "4500", "id_prov": "1", "cantidad": "1", "id_bodega": "1", "nom_prov": "Proveedor de prueba 1", "modelo": "MECANIZADOS Y OTROS", "nombre": "Bodega Conchalí", "status": "EN BODEGA", "id_cat": "16" }, { "id_stock": "6", "oc_id": "4", "detalle": "Revisión de ruedas", "cat_id": "16", "codigo": "m20.3", "marca": "", "parte": "", "precio_in": "4500", "id_prov": "1", "cantidad": "1", "id_bodega": "1", "nom_prov": "Proveedor de prueba 1", "modelo": "MECANIZADOS Y OTROS", "nombre": "Bodega Conchalí", "status": "EN BODEGA", "id_cat": "16" }]; }]);
Check code http://jsfiddle.net/eCJ47/44/
Sorry for the english is not my native language. Thanks !!
ng-model. Is that what you want? Wouldn't it be clean if you assignng-true-value="{{value.id_stock}}"?