mardi 15 mars 2016

Using checklist-model to get all checked checkboxes in Angular

I have a table from an array, on the first column I have a hidden checkbox. When I click on a button, the checkboxes and a confirmation button appears. I mark the rows (with the checkbox) and click on submit button. I want to show an alert with the id from all the checked rows. I'm trying with checklist-model but it's not working. It's my first project with angular:

    <div class="row" ng-controller="AtributsGenericsCtrl">
        <ol class="breadcrumb">
            <li><a href="#/error/error">Menu principal</a></li>
            <li><a href="#/tipusactius">Llistat de tipus d'actius</a></li>
            <li class="active">Atributs generics per a tots els actius</li>
        </ol>
        <ul class="nav nav-pills">
          <li role="presentation"><a href="#/atributs/atributsgenerics/alta/">Alta d'atributs generics</a></li> 
          <li role="presentation"><a href ng-click="show = !show">Elimina atributs</a></li>   
          <li role="presentation"><a href ng-show="show" ng-click="confirm()">Confirma</a></li>  
        </ul>
        <div class="col-md-10">
            <div class="row"></div>
            <table class="table">
                <tr>
                    <th></th>
                    <th><a href="" ng-click="sortField = 'nom'; reverse = !reverse">Atribut</a></th>
                    <th><a href="" ng-click="sortField = 'valor'; reverse = !reverse">Tipus</a></th>
                </tr>
                <tr ng-repeat="atribut in atributsGenerics | orderBy:sortField:reverse | filter: filtra">
                    <td><input type="checkbox" ng-show="show" checklist-model="opt" checklist-value="atribut.id"></td>
                    <td>{{atribut.nom}}</td>
                    <td>{{atribut.valor}}</td>
                </tr>
            </table>
        </div>
    </div>
</div>

The controller:

// CTRL atributs generics          
            assets.controller('AtributsGenericsCtrl', function ($scope, $http, $window) {
                $http.get('http://ift.tt/1LoDSKN').success(function (data) {
                    $scope.atributsGenerics = data;
                });

                $scope.show = false;


                // Ordena taula per id desc
                $scope.sortField = 'idtipus_actius';
                $scope.reverse = false;
                $scope.u = {
                    r: []
                };

                $scope.opt = [];

                $scope.confirm = function () {
                    $window.alert('abans bucle');
                    angular.forEach($scope.opt, $scope.cc);
                    $window.alert('despres bucle');
                }

                $scope.cc = function () {
                    $window.alert('durant bucle');
                }
            });

The array opt (which contains all markedrows) it's no getting the value. I've been looking another examples. But still doesn't work. Any help?

Regards




Aucun commentaire:

Enregistrer un commentaire