Javascript 角度:开关内部重复,内存问题
我正在用不同的td组件构建一个tr 有许多不同的td组件可用,只会渲染少数组件Javascript 角度:开关内部重复,内存问题,javascript,angularjs,angularjs-ng-repeat,ng-switch,Javascript,Angularjs,Angularjs Ng Repeat,Ng Switch,我正在用不同的td组件构建一个tr 有许多不同的td组件可用,只会渲染少数组件 <tr ng-repeat='row in rowlist'> <td ng-repeat='columnType in columnsThatShouldBeDisplayed' ng-switch='columnType'> <colA ng-switch-when='typeA'></colA> <colB ng-switch-when=
<tr ng-repeat='row in rowlist'>
<td ng-repeat='columnType in columnsThatShouldBeDisplayed' ng-switch='columnType'>
<colA ng-switch-when='typeA'></colA>
<colB ng-switch-when='typeB'></colB>
<colC ng-switch-when='typeC'></colC>
// and so on..
<td>
</tr>
这需要很多内存。看起来我的所有组件都已构建,但每次迭代只显示一个组件
正确的做法是什么?
关于如何绕过问题并以另一种方式执行的提示?您必须将ng开关作为repeat元素的属性
我能要求一件简单的事吗?您能提供一个您正在尝试构建的简单表结构吗?当从DOM中删除不匹配的开关内容时,图像、HTML、所有内容都将被精细化,因此最终的DOM将只是所需的最小内容。所以它不需要很多内存。
<div ng-controller="formPersonalInfoController">
<form role="form">
<div ng-repeat="Country in Countries" class="animate-switch-container" ng-switch on="Country.name">
<div>
<div class="animate-switch" ng-switch-when="Andorra">
<div class="form-group">
<div class="col-md-6">
<label class="text-info">{{ Country.name }} :</label>
</div>
<div class="col-md-6">
<textarea id="{{Country.Id}}" class="form-control" placeholder="{{ Country.name }}"></textarea>
</div>
</div>
</div>
<div class="animate-switch" ng-switch-default>
<div class="form-group">
<div class="col-md-6">
<label class="text-info">{{ Country.name | uppercase }} :</label>
</div>
<div class="col-md-6">
<input id="{{Country.Id}}" class="form-control" type="text" placeholder="{{ Country.name }}" />
</div>
</div>
</div>
</div>
</div>
</form>
</div>