MRu MRu - 1 year ago 85
AngularJS Question

How to show the most recent messages?

My task is actually trying to make a broadcast messages to show the most recent messages in a limited number only. I have found how to limit the messages in this thread. But right now i am struggling on how to show only the latest messages. I'm new in this angular, hope you can explain it in a simple way please. Thank you.

If there's 10 messages:

message 1
message 2
message 3
message 4
message 5
message 6
message 7
message 8
message 9
message 10

There result should be:

message 6
message 7
message 8
message 9
message 10

Here is the code:

<div ng-repeat="score in scores | limitTo: limit">

In controller:

var limitStep = 5;
$scope.limit = limitStep;
$scope.incrementLimit = function() {
$scope.limit += limitStep;
$scope.decrementLimit = function() {
$scope.limit -= limitStep;

Answer Source

You can do limitTo: -limit, - helps to select from the last.

<div ng-repeat="score in scores | limitTo: -limit">


Creates a new array or string containing only a specified number of elements. The elements are taken from either the beginning or the end of the source array, string or number, as specified by the value and sign (positive or negative) of limit.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download