简体   繁体   中英

more link for angular ng-repeat show first few items

I have a scenario where I have Array of objects and I wanted to display on first few of them (should be configurable).

var users = [{id:1234, name:'ABCD', role: 'XXX', lastLogin: 'XXXX'},
            {id:1235, name:'ABCDE', role: 'XXX', lastLogin: 'XXXX'},
            {id:1236, name:'ABCDF', role: 'XXX', lastLogin: 'XXXX'},
            {id:1237, name:'ABCDG', role: 'XXX', lastLogin: 'XXXX'},
            {id:1238, name:'ABCDH', role: 'XXX', lastLogin: 'XXXX'},
            {id:1239, name:'ABCDI', role: 'XXX', lastLogin: 'XXXX'}]

  <div ng-repeat="user in users">
       {{user.name}}({{user.id}}) {{$last ? ',' : ''}}
  </div>

I just want to display first 2 records as ABCD(1234), ABCDE(1235) + 4 more. and display the other records on hover with a tooltip as

ABCDF(1236)
ABCDG(1237)
ABCDH(1238)
ABCDI(1239)

with each data on new line on tooltip.

Try to use limitTo

Like this

<div ng-repeat="user in users | limitTo: limit">
       {{user.name}}({{user.id}}) {{$last ? ',' : ''}}
</div>

JS

$scope.limit=2;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM