html - Send row info to angularjs controller when checkbox in row is clicked -


i have html code uses angularjs show table. on table, there checkbox on each row.

the table looks this; enter image description here

here html code.

<div ng-app ng-controller="checkctrl">     <table class="table table-hover data-table sort display" style="width:100%">         <thead>         <tr>             <th class="serial_">                 serial             </th>             <th class="name_">                 name             </th>             <th class="id_">                 id             </th>             <th class="on_off_">                 on/off             </th>         </tr>         </thead>         <tbody>         <tr ng-repeat="item in check_items">             <td>{{item.serial}}</td>             <td>{{item.name}}</td>             <td>{{item.id}}</td>             <td> <input type="checkbox" ng-checked="item.on_off == '1'"></td>         </tbody>     </table> </div> 

here angularjs controller code.

controller('checkctrl', ['$scope', '$http', 'configuration',      function ($scope, $http, $configuration) {         var url_api = $configuration.host + "cloe/webroot/cloe-cloud/app/api.json";         $http.get(url_api).success(function(data)         {             $scope.check_items = data;         }); 

this want. when user clicks on checkbox, information regarding items on particular row belonging clicked checkbox sent angualrjs controller function processing. information should include serial, name, id , new state of on/off after clicking on checkbox.

i using angularjs v1 , twitter bootstrap.

edit: edited original question details indicate row information should sent whenever checkbox clicked , not when checkbox enabled.

we can use ng-change send row data controller object. after that, can retrieve row data following:

var serial = row.serial; var name = row.name; var id = row.id; var onoff = row.on_off; 

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>  <div ng-app="app" ng-controller="checkctrl">      <table class="table table-hover data-table sort display" style="width:100%">          <thead>          <tr>              <th class="serial_">                  serial              </th>              <th class="name_">                  name              </th>              <th class="id_">                  id              </th>              <th class="on_off_">                  on/off              </th>          </tr>          </thead>          <tbody>          <tr ng-repeat="item in check_items">              <td>{{item.serial}}</td>              <td>{{item.name}}</td>              <td>{{item.id}}</td>              <td> <input type="checkbox" ng-checked="item.on_off == '1'" ng-click="rowselected(item)"></td>          </tbody>      </table>  </div>    <script>    var app = angular.module('app',[]);    app.controller('checkctrl', ['$scope', '$http', function ($scope, $http) {        $scope.check_items =           [             {               serial:'test serial',               name:'test name',               id : 10,               on_off : '1'             }          ];          $scope.rowselected = function(row)        {            console.log(row);        };     }]);    </script>


Comments

Popular posts from this blog

php - How to add and update images or image url in Volusion using Volusion API -

javascript - jQuery UI Splitter/Resizable for unlimited amount of columns -

javascript - IE9 error '$'is not defined -