0

我正在构建一个内部tr包含不同td 组件的组件。

有许多不同的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='typeB'></colB>
    <colC ng-switch-when='typeC'></colC>
    // and so on..
  <td>
</tr> 

这会占用大量内存。似乎我的所有组件都已构建,但每次迭代只显示一个。

这样做的正确方法是什么?关于如何解决问题并以另一种方式解决问题的提示?

4

1 回答 1

0

您必须将 ng-switch 作为重复元素的属性包含在内

<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>
于 2014-11-18T21:58:54.950 回答