I have a toggle button in a table row, once clicked, I'd like to leave the last clicked row visible, while hiding all other rows of the table.
This is done using two flags: 'showAll' (global) and 'showGridRow'- per row.
A row is displayed if one of the flags is true: ng-show="{{showAll}}||product.showGridRow"
code:
$scope.showAll = showAll;
$scope.toggleReadings = function toggleReadings(product) {
if (product.showGridRow == undefined) {
//if undefined, this is first click - set to false so it will be enabled immediatelly
product.showGridRow = false;
}
product.showGridRow = !product.showGridRow;
//if true, hide all others, else show all
showAll = !product.showGridRow;
};
<table class="table table-striped">
<thead>
<tr>
<th>Product ID</th>
<th>Product Name</th>
<th>Topic</th>
<th>Active</th>
<th>Readings</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="product in products" ng-show="{{showAll}}||product.showGridRow">
<td>{{product.productId}}</td>
<td>{{product.productName}}</td>
<td>{{product.topic}}</td>
<td>{{product.Active}}</td>
<td>
<input type="button" value="..." ng-click="toggleReadings(product)" >
</td>
</tr>
</tbody>
</table>
My Question:
This works only when placing a breakpoint at the beginning of the toggleReadings() function and debugging the code. While running the code "normally" nothing happens. What am I missing? Thanks!
filterfilter.ng-repeatcreates a child scope for each row, causing scope inheritance issues with the$scope.showAllprimitive. thetoggleReadings(product)function will, in effect, create a new$scope.showAllproperty for each row the first time the button is clicked, and will not affect the parent property, nor any of the properties created so far within each row other than itself.ng-showanyway.ng-show.