簡體   English   中英

如何顯示最新消息?

[英]How to show the most recent messages?

我的任務實際上是嘗試使廣播消息僅顯示有限數量的最新消息。 我發現了如何限制該線程中的消息。 但是現在,我在如何僅顯示最新消息方面苦苦掙扎。 我是這個新手,希望您能以簡單的方式進行解釋。 謝謝。

如果有10條消息:

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

結果應該是:

message 6
message 7
message 8
message 9
message 10

這是代碼:

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

在控制器中:

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

您可以執行limitTo: -limit-幫助從上一個中選擇。

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

LimitTo

創建僅包含指定數量的元素的新數組或字符串。 元素取自源數組,字符串或數字的開頭或結尾,由限制的值和符號(正或負)指定。

您可以通過切片值來做到這一點,

 <ul ng-repeat="strVal in arrVal.slice(5, 10)">
    <li>{{strVal}}</li>
  </ul>

或使用角度特征LimitTo

<div ng-repeat="strVal in arrVal| limitTo: 10 | limitTo: -5">{{strVal }}</div>

演示

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM