mercredi 4 février 2015

Maintain scroll position after adding items to array in ng-repeat


Have list of messages displayed via ng-repeat, when user scrolls to top older messages are loaded via ion refresher. Desired behavior is for older messages to be added above the current messages, and the scroll position of current messages to be maintained.


HTML



<ion-refresher
pulling-icon="ion-ios-arrow-thin-down"
refreshing-text="loading messages"
on-refresh="moreMessages()">
</ion-refresher>

<div ng-repeat="message in convo.messages" >
{{message.text}}
</div>
</ion-content>


JS



$scope.moreMessages = function(){
$scope.convo.messages = olderMessages().concat($scope.convo.messages)
}


Problem is when more messages is called, the ion-content scrolls to the top (stays at the top?).


How to set scroll position so loading older messages just makes the older messages accessable by scrolling up? Like it does in iMessage, or other chat apps?





Aucun commentaire:

Enregistrer un commentaire