0

Hi I have created a table using scrollable-table and now I need to add a checkbox in the table for every row. How to change the value of the checkbox to checked/unchecked based on the value of the model. i.e if the value of the model is true which I am getting from mysql table then the checkbox should be checked for the particular row. The other values which are false should remain false.

Janani S
  • 21
  • 5

2 Answers2

0
//== You can define a directive to bind click function, html: &lttr toggle-model="yourScopeModel"&gt&lt/tr&gt 

angular.module('CommonDirective', []).directive('toggleModel', function() {
        return {
            restrict: 'A',
            scope:{
                toggleModel: '&'
            },
            link: function(scope, element, attrs) {
                angular.element(element).click(function(){
                    scope.toggleModel = !scope.toggleModel;
                });
            }
        };
    });

//==This is just an example code (not test yet). Hope to help you!

  • Hi Thanks blake. But now the requirement has changed now I need to use checkbox. On click I am doing the update in the sql table and again I am calling the function which has the select statement to get the current value from the table. But all the time the checkbox is not showing correct value based on the value present in mysql table. – Janani S Jul 10 '18 at 07:01
0

The mistake I made was when comparing for checked value ng-model was in string and for checkbox it is boolean value. So I should have given that inside quotes while checking. This is the syntax now I have used.

<input type="checkbox" id="'#toggleeventtoggleApp_' + $Index" ng-true-value="'true'" ng-false-value="'false'"  ng-model="x.userinput" ng-change="AutoStartToggle($index,x);"><br>
Janani S
  • 21
  • 5