如何使重复运行仅10次

时间:2016-05-25 15:49:21

标签: angularjs

我必须修改乐山客户端的UI。目前它的设置方式,它在浏览器中显示客户端的每个实例。我如何让它只显示10个客户端,虽然我仍然会创建数百个客户端?我尝试修改下面的代码,用于ng repeat和ng click,但唯一改变的是我停止显示任何客户端。

    <tbody>
        <tr ng-repeat="client in clients" ng-click="showClient(client)">
            <td><a ng-href="#/clients/{{client.endpoint}}"> <strong>{{client.endpoint}}</strong></a> </td>
            <td>{{client.registrationId}}</td>
            <td>{{client.registrationDate | date:'medium'}}</td>
            <td>{{client.lastUpdate | date:'medium'}}</td>
            <td><i class="glyphicon glyphicon-info-sign" tooltip-html-unsafe="{{clientTooltip(client)}}"></i></td>
            <td><span ng-class="{hidden: client.secure == false}" class="glyphicon glyphicon-lock" tooltip-html-unsafe="Communication over DTLS"></span></td>
        </tr>
    </tbody>

2 个答案:

答案 0 :(得分:0)

<tbody>
        <tr ng-repeat="client in clients | limitTo:10" ng-click="showClient(client)">
            <td><a ng-href="#/clients/{{client.endpoint}}"> <strong>{{client.endpoint}}</strong></a> </td>
            <td>{{client.registrationId}}</td>
            <td>{{client.registrationDate | date:'medium'}}</td>
            <td>{{client.lastUpdate | date:'medium'}}</td>
            <td><i class="glyphicon glyphicon-info-sign" tooltip-html-unsafe="{{clientTooltip(client)}}"></i></td>
            <td><span ng-class="{hidden: client.secure == false}" class="glyphicon glyphicon-lock" tooltip-html-unsafe="Communication over DTLS"></span></td>
        </tr>
    </tbody>

答案 1 :(得分:0)

使用 ng-if

<div ng-repeat="i in values">
    <div ng-if="i < 3">Hello</div>
</div>

working example

或使用辅助变量只显示您想要的结果