I have an ng-repeat list that starts with 10 items. I would like to add new items at the end of the list (bottom) If I currently run the function it will add items to the top of my list.
I know that you can add items with .push() and .unshift() but this is not working with the code I use.
This is my code (I use a code snippet from Pubnub to fetch history items):
$scope.messages = [];
$scope.loadMore = function() {
var timeToken = $('.lastMessage').attr('timetoken');
console.log(timeToken);
// Populate message history
PubNub.ngHistory({
start: timeToken,
channel: $scope.channel,
count: 5,
});
};
html:
<ion-item ng-repeat="message in messages track by $index">
You can use an orderby with ng-repeat. It looks like you have a time value in each element, you can use that to order the list.
<tr ng-repeat="item in history | orderBy:'start'">
if you have an id in the elements you can also use "track by" so if you have for instance an id field. This allows angular to show duplicates. However this doesn't seem to be your issue. from their wiki:
By default, ngRepeat does not allow duplicate items in arrays. This is because when there are duplicates, it is not possible to maintain a one-to-one mapping between collection items and DOM elements.
If you do need to repeat duplicate items, you can substitute the default tracking behavior with your own using the track by expression.
<tr ng-repeat="item in history track by $id">