AngularJS ng开关渲染顺序
我有一个关于ng开关渲染顺序的问题 代码(HTML):AngularJS ng开关渲染顺序,angularjs,Angularjs,我有一个关于ng开关渲染顺序的问题 代码(HTML): <div ng-controller="testCtrl"> <button ng-click="v1 = !v1">toggle v1</button> <table class="table table-bordered"> <tbody> <tr ng-switch on="v1"> <th ng-switch
<div ng-controller="testCtrl">
<button ng-click="v1 = !v1">toggle v1</button>
<table class="table table-bordered">
<tbody>
<tr ng-switch on="v1">
<th ng-switch-when="true">V1</th>
<th ng-repeat="item in datas">{{item}}</th>
</tr>
</tbody>
</table>
var myApp = angular.module('myApp',[]);
function testCtrl($scope) {
$scope.datas = ['A', 'B'];
}
我希望通过命令得到一个结果:
V1 A B
但是相反,输出首先显示ng repeat items,然后是ng switch when语句
为什么
有没有其他的解决方案可以按照我的预期顺序来做这件事
============================
更新(2014/04/02):
以下是为什么ng show不是一个选项的解释
我写了一个如下的指令表:
<table class="table table-bordered">
<thead>
<tr>
<th ng-show="checkbox"><input type="checkbox" /></th>
<th ng-repeat="col in columns">{{col.text}}</th>
</td>
</thead>
<!-- body is ignored -->
</table>
{{col.text}}
checkbox变量用于控制是否应显示复选框输入
在我应用JQuery ColResize之前,这一切都很正常
当复选框变量为false时,ng show隐藏第一个th元素
隐藏的th元素会导致JQuery ColResize出现故障
因此,ng show不适合这种情况
========================
当前解决方案:
我目前的解决方案是使用ng开关来分离两个表元素
并使用一个变量来决定绘制哪个表
像这样:
<div ng-switch on="checkbox">
<table ng-switch-when="true">
<tr>
<th><input type="checkbox" /></th>
<th ng-repeat="col in columns">{{col.text}}</th>
</tr>
<!-- body is ignored -->
</table>
<table ng-switch-default>
<tr>
<th ng-repeat="col in columns">{{col.text}}</th>
</tr>
<!-- body is ignored -->
</table>
</div>
{{col.text}}
{{col.text}}
虽然这解决了问题,但不是一个好的解决方案
但除非我找到另一个解决方案
我想我只能满足于此。您可以使用
ng show
而不是ng开关
,如图所示
V1
{{item}}
ng show在DOM元素周围应用样式,其中指令分别用于显示/隐藏。在您的情况下,标题已正确编译,但仅根据提供给
ng show
的条件显示。感谢您的回答。“ng秀”将解决“订单”问题。但在我的具体案例中,“ng show”会引起另一个问题。这应该在问题之前提到:)。详细说明使用ng show
有什么问题。很抱歉。我将编辑问题以进行解释。
<tr>
<th ng-show="v1">V1</th>
<th ng-repeat="item in datas">{{item}}</th>
</tr>