In scrollable-table to change the state of the check box based on the model value

55 Views Asked by At

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.

2

There are 2 best solutions below

1
On
//== You can define a directive to bind click function, html: <tr toggle-model="yourScopeModel"></tr> 

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!

0
On

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>