【发布时间】:2017-05-30 12:09:52
【问题描述】:
我正在使用 AngularJS 1.6.x 并使用ng-repeat 构建一个表,如下所示。但是,现在我需要根据一些动态布尔条件显示一个新列,即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>
在控制器端:
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);
});
问题是条件在开始时只评估一次,在构造表时,以后无论isDynamicVisible范围变量发生变化,它都会保持最初的状态。我也尝试过使用ng-show,但没有成功。
更新:当用户将鼠标悬停在 D3 JS 散点图的数据点上时,控制器会更改 isDynamicVisible。
【问题讨论】:
-
isDynamicVisible是布尔值还是函数? -
你能在
.on()之前添加东西吗? -
有点无关紧要,但没关系。我已经测试过那里的代码可以正确执行等等。
-
避免使用
jquery,并使用ng-mouseover和ng-mouseout指令。
标签: javascript angularjs d3.js