I have a table that's populated with records from an object retrieved from a service captured using AngularJS. I have checkbox in the table that enables that row to be edited. Within the row, I have a select box that I need to have its default value set to the original value in the row when I click the "Edit" checkbox in the row while still populating the select with all the other values from which to choose.
Below is the code that's populating the table and the select box.
<thead>
<tr>
<th class="col-lg-2">Sub Program</th>
<th class="col-lg-6">Description</th>
<th class="col-lg-2">Program</th>
<th class="col-lg-1">Edit</th>
<th class="col-lg-1">Update/Delete</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="timeAllocationSubProgram in timeAllocationSubPrograms">
<td ng-hide="checked">{{timeAllocationSubProgram.subProgramName}}</td>
<td ng-hide="checked">{{timeAllocationSubProgram.subProgramDescription}}</td>
<td ng-hide="checked">{{timeAllocationSubProgram.programName}}</td>
<td ng-show="checked">
<input class="form-control" value="{{timeAllocationSubProgram.subProgramName}}"
ng-model="timeAllocationSubProgram.subProgramName" />
</td>
<td ng-show="checked">
<input class="form-control" value="{{timeAllocationSubProgram.subProgramDescription}}"
ng-model="timeAllocationSubProgram.subProgramDescription" />
</td>
<td ng-show="checked">
<select class="form-control" ng-options="timeAllocationProgram as timeAllocationProgram.programName
for timeAllocationProgram in timeAllocationPrograms track by timeAllocationProgram.programName" ng-model="timeAllocationProgram"
ng-change="selectProgram(timeAllocationProgram)"></select>
</td>
<td>
<input type="checkbox" ng-model="checked" aria-label="Toggle ngShow"/>
</td>
<td>
<button class="btn btn-xs btn-primary" ng-click="editTimeAllocationSubProgram(timeAllocationSubProgram)"
ng-show="checked">
Update
</button>
<button class="btn btn-xs btn-primary" ng-click="deleteTimeAllocationSubProgram(timeAllocationSubProgram)"
ng-hide="checked">
Delete
</button>
</td>
</tr>
</tbody>
</table>