简体   繁体   中英

AngularJS: ng-repeat index and limit error

I'm using AngularJS 1.2.13.

This is not working. I'm getting an error of couple dozen lines with minimized code, so that's not helpful. Can someone tell me what could be wrong here?

My goal is this: display data from two-dimensional array in a table in a reverse order, limit number of rows to 5. The data is being updated live (rows added to array).

<tr ng-repeat="row in data track by $index | limitTo:5 | reverse">
    <td>{{$index}}</td>
    <td ng-repeat="col in row">
        {{col}}
    </td>
</tr>                   

Another thing: is it possible to display something like {{$index + 1}} ? As in - display data as 1-based indexing instead of zero based indexing.

UPDATE: This is the error I'm getting on page refresh:

Error: [$injector:unpr] http://errors.angularjs.org/1.2.13/$injector/unpr?p0=reverseFilterProvider%20%3C-%20reverseFilter
E/<@http://localhost:9001/assets/javascripts/angular.min.js:6
ac/l.$injector<@http://localhost:9001/assets/javascripts/angular.min.js:32
c@http://localhost:9001/assets/javascripts/angular.min.js:30
ac/p.$injector<@http://localhost:9001/assets/javascripts/angular.min.js:32
c@http://localhost:9001/assets/javascripts/angular.min.js:30
Cc/this.$get</<@http://localhost:9001/assets/javascripts/angular.min.js:116
Za.prototype.filter@http://localhost:9001/assets/javascripts/angular.min.js:159
Za.prototype.filterChain@http://localhost:9001/assets/javascripts/angular.min.js:159
Za.prototype.statements@http://localhost:9001/assets/javascripts/angular.min.js:159
Za.prototype.parse@http://localhost:9001/assets/javascripts/angular.min.js:156
zd/this.$get</<@http://localhost:9001/assets/javascripts/angular.min.js:92
ye</<.link@http://localhost:9001/assets/javascripts/angular.min.js:185
I@http://localhost:9001/assets/javascripts/angular.min.js:49
h@http://localhost:9001/assets/javascripts/angular.min.js:42
h@http://localhost:9001/assets/javascripts/angular.min.js:42
h@http://localhost:9001/assets/javascripts/angular.min.js:42
h@http://localhost:9001/assets/javascripts/angular.min.js:42
h@http://localhost:9001/assets/javascripts/angular.min.js:42
h@http://localhost:9001/assets/javascripts/angular.min.js:42
h@http://localhost:9001/assets/javascripts/angular.min.js:42
Y/<@http://localhost:9001/assets/javascripts/angular.min.js:42
ue</<.link@http://localhost:9001/assets/javascripts/angular.min.js:183
I@http://localhost:9001/assets/javascripts/angular.min.js:49
h@http://localhost:9001/assets/javascripts/angular.min.js:42
Y/<@http://localhost:9001/assets/javascripts/angular.min.js:42
ba/<@http://localhost:9001/assets/javascripts/angular.min.js:43
p@http://localhost:9001/assets/javascripts/angular.min.js:47
te</<.compile/</</<@http://localhost:9001/assets/javascripts/angular.min.js:183
q/g.success/<@http://localhost:9001/assets/javascripts/angular.min.js:67
Bd/e/l.promise.then/B@http://localhost:9001/assets/javascripts/angular.min.js:94
Bd/e/l.promise.then/B@http://localhost:9001/assets/javascripts/angular.min.js:94
Bd/f/<.then/<@http://localhost:9001/assets/javascripts/angular.min.js:95
Cd/this.$get</h.prototype.$eval@http://localhost:9001/assets/javascripts/angular.min.js:103
Cd/this.$get</h.prototype.$digest@http://localhost:9001/assets/javascripts/angular.min.js:101
Cd/this.$get</h.prototype.$apply@http://localhost:9001/assets/javascripts/angular.min.js:104
g@http://localhost:9001/assets/javascripts/angular.min.js:68
I@http://localhost:9001/assets/javascripts/angular.min.js:72
qd/</y.onreadystatechange@http://localhost:9001/assets/javascripts/angular.min.js:73

<!-- ngRepeat: row in score track by $index | limitTo:5 | reverse -->

reverse filter is no out of the box filter of angularjs. You have to implement yourself. An example can be found here: angular ng-repeat in reverse

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