user308553 user308553 - 10 months ago 49
AngularJS Question

angular ng-repeat dynamic generate checkbox and string

I have a directive that host a template that takes in a JSON (that contain some data for building a table, and some method to manipulate the data) and generate a table.

relevant code in the template:

<table class="table" id="table_{{}}">
<th ng-repeat="header in table.headers track by $index">{{header}}</th>
<tr ng-repeat="row in table.rows track by $index">
<td ng-repeat="item in row track by $index"

an example of a json being fed into this template

$scope.searchTable = {
headers: ["title", "deleted"],
rows: [ ["ABC", true],
["DEF", false] ],


My question is:

sometimes the table require a column with checkboxs, depending on the data. Is there any way to change my template so that when necessary it will generate a column of checkbox instead of just string?

For example: For the JSON example above, let's say I want the column of
to be checkboxes. So if an entry is deleted that row will have a unchecked checkbox under the

Does this make any sense? Everything is generated dynamic, so I have no idea which column will be checkboxes. It all depends on the data the page gets from the server. So in the example: the server will tell client which entry is readable, then I will generate that JSON and feed it to the template. How should I structure my JSON and the template

Is this even doable? Any tips?

  <tr ng-repeat="row in table.rows track by $index">
          <td ng-repeat="item in row track by $index">
          <div data-ng-if="item.type!=='checkbox'" ng-Click="table.selectedRow(row)"></div>
          <div data-ng-if="item.type==='checkbox'"> <input type="checkbox" /></div>