我需要根据控制器中的范围值显示/隐藏表的tr标记。我已经编写了如下所示的代码但是class =" ng-hide"尽管我已经用正确的语法声明了我的ng-show,但每次都会自动附加tr标签。
<div ng-show="IsParentExist">
<table>
<thead>...</thead>
<tbody>
<tr ng-show="noValueExist">
<span>There are no records to show here..</span>
</tr>
<tr ng-repeat....>
<td> </td>
</tr>
</tbody>
</table>
</div>
如果在DOM中呈现如下
,则会出现问题<div ng-show="IsParentExist">
<span>There are no records to show here..</span>
<table>
<thead>...</thead>
<tbody>
<tr class="ng-hide" ng-show="noValueExist">
</tr>
<tr ng-repeat....>
<td> </td>
</tr>
</tbody>
</table>
</div>
我在控制器中分配了范围变量,如下所示
$scope.noValueExist = true;
答案 0 :(得分:1)
在控制器中将noValueExist的值设置为true之前,angular默认将类设置为ng-hide。在控制器中添加此行。
$scope.noValueExist = true;
答案 1 :(得分:0)
尝试将ng-show="noValueExist"
替换为ng-hide="!noValueExist"
<tbody>
<tr ng-hide="!noValueExist">
<td>There are no records to show here.</td>
</tr>
<tr>
<td></td>
</tr>
</tbody>
在您的控制器中,初始化您的值。
$scope.noValueExist = false;
当您需要显示<tr>
元素时,请将此值设置为true。
$scope.noValueExist = true;
我希望这会对你有所帮助。
答案 2 :(得分:0)
正如用户@ cst1992所提到的那样,问题是没有包含span。
答案 3 :(得分:-1)
跨度变得错位,因为内部不支持&#39; tr&#39;标签。 你需要使用&#td&#39;标记以显示表格内的内容。
更换&#39; span&#39;与&#39;&#39;标记,它在DOM中呈现如下。
{{1}}