单击时运行ng repeat(当ng show为true时)

Run ng-repeat on-click (when ng-show is true)?

本文关键字:ng true show 运行 repeat 单击      更新时间:2023-09-26

我有一个用ng-repeat填充的表。表格有100行,如果你点击任何一行,就会显示新的表格,(带有ng-show)对产品有更深入的描述。但ng-repeat速度较慢,在页面加载时生成101表,这降低了我的web应用程序的性能。有没有一种方法,使用angular(没有外部库),只在用户单击某行时运行ng-repeatng-show为true)?

注意:每个隐藏表都是唯一的。

这是我的html表格:

<tbody>
    <tr ng-repeat-start="car in sortedCarList" ng-click="showTable(car)">
        <td><a target="_blank" href="{{car.carLink}}">{{car.name}}</a></td>
        <td>{{car.review}}</td>
        <td>{{car.rating}}</td>
        <td>{{car.fiveStarPercent}}</td>
        <td>{{car.recommended}}</td>
        <td>{{car.price}}</td>
    </tr>
    <tr ng-repeat-end ng-show="modelRow.activeRow==car.name && showDetails && car.allReviews.length!=0" class="hidden-table">
        <td colspan="6">
            <table class="table table-striped table-bordered table-condensed table-hover">
                <thead>
                    <tr>
                        <th>Year</th>
                        <th>Reviews</th>
                        <th>Rating <span class="fiveStar">/5</span></th>
                        <th>Recommended</th>
                        <th>Reliability Rating</th>
                        <th>Performance Rating</th>
                        <th>Running Costs Rating</th>
                    </tr>
                </thead>
                <tbody ng-repeat="rev in car.allReviews">
                    ....

尝试使用ng-if而不是ng-show来切换嵌套表。这应该会延迟嵌套表中的任何ng-repeat,直到它显示出来。