1

I have checkboxes with table headers, i want to hide the table columns and rows based on the checkbox click,

<ul>
    <li ng-repeat="opt in fieldvalues"><input type="checkbox" ng-model="checked" value="{{opt}}" />{{opt}}</li>
 </ul>

<table>
    <tr>                                
      <th ng-show="checked=='true'">Activity ID</a></th>
      <th>Activity Description</th>
    </tr>
<tr ng-repeat="nm in makerQueueData">
  <td ng-show="checked=='true'">{{nm.formattedIdentifier}}</td>
  <td>{{nm.description}}</td>
</tr>
</table>

I tried but no luck.

5
  • dont u have ng-repeat on table ? Commented Jan 23, 2015 at 5:01
  • ng-show="checked==true" Commented Jan 23, 2015 at 5:05
  • yes, ng-repeat="nm in makerQueueData Commented Jan 23, 2015 at 5:08
  • 2
    Why do you have several checkboxes, all bound to 'checked'? That doesn't make much sense. Commented Jan 23, 2015 at 7:01
  • Am I right that you want to have a checkbox for each item in fieldvalues and each item has its own table? Commented Jan 23, 2015 at 7:53

2 Answers 2

1
<ul>
<li ng-repeat="opt in fieldvalues"><input type="checkbox" ng-model="checked" value="{{opt}}" />{{opt}}</li>
</ul>




  <table>
         <tr>                                
         <th ng-show="checked"><a>Activity ID</a></th>   

         //here checked gets bool value itself based on selection. you don't need to compare it to string 'true'.

         //keep in mind i assume {{checked}} returns only bool value
         <th>Activity Description</th>
        </tr>


        <tr ng-repeat="nm in makerQueueData">
          <td ng-show="checked">{{nm.formattedIdentifier}}</td>
          <td>{{nm.description}}</td>
        </tr>
        </table>

Working fiddle for your : http://jsfiddle.net/b69pkeLd/1/ Let me know if any issue occurs.

Sign up to request clarification or add additional context in comments.

Comments

0

I hope this is what you are looking for:

var myApp = angular.module('myApp',[]);

function MyCtrl($scope) {
    $scope.fieldvalues = [
        {text: 'Test1', checked: false}, 
        {text: 'Test2', checked: false}
    ];
    $scope.makerQueueData = [
        'Whatever your', 'data is'
    ];
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>

<div ng-app="myApp" ng-controller="MyCtrl">
    <div ng-repeat="opt in fieldvalues">
        <input type="checkbox" id="checkbox-{{$index}}" ng-model="opt.checked" value="{{opt.text}}" />
        <label for="checkbox-{{$index}}">{{opt.text}}</label>
        <table ng-show="opt.checked">
            <tr>                                
                <th>Activity ID</a></th>
                <th>Activity Description</th>
            </tr>
            <tr ng-repeat="nm in makerQueueData">
                <td ng-show="opt.checked'">{{$index}}</td>
                <td>{{nm}}</td>
            </tr>
        </table>
    </div>
</div>

Moreover, use <label> for type="checkbox" description. This makes the label clickable.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.