I'm using AngularJS 1.6.x and build a table using ng-repeat
as shown below. However, now I need to show a new column depending on some dynamic boolean condition i.e. isDynamicVisible
:
<table>
<thead>
<tr>
<th id="name">Name</th>
<th id="mean">Mean</th>
<th ng-if="isDynamicVisible">Dynamic</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="data in displayedPathStatistics" ng-class="{selected: (histogramData.selected === data.name)}"
ng-click="selectPathOutputRow(data.name)">
<td>{{data.displayName}}</td>
<td>{{data.Mean}}</td>
<td ng-if="isDynamicVisible">{{dynamicVal}}</td>
</tr>
</tbody>
</table>
On the controller side:
constructor(private $window: IWindowService, private $rootScope: IRootScopeService, private $scope:IReportCtrlScope, private $location:ng.ILocationService, private remoteServices: RemoteServices) {
$scope.isDynamicVisible = false;
// ...
objects.selectAll(".dot")
.data(data)
.enter().append("circle")
.classed("dot", true)
.attr("r", function (d) {
return 6 * Math.sqrt(2.0 / Math.PI);
})
.attr("transform", transform)
.style("fill", colorVal)
.on("mouseover", function(d) {
$scope.isDynamicVisible = true;
return tip.show(d);
})
.on("mouseout", function(d) {
$scope.isDynamicVisible = false;
return tip.hide(d);
});
The problem is that the condition is evaluated only once at the beginning and upon constructing the table, later no matter that the isDynamicVisible
scope variable changes it will stay how it initially was. I have also tried using ng-show
without success.
UPDATE: the isDynamicVisible
is changed from the Controller specifically when the user hovers over a data point of a D3 JS scatter plot.