是否可以直接转到ng-repeat生成的div的底部?

时间:2015-12-17 12:30:11

标签: angularjs

我有一个ng-repeat,它在聊天中显示聊天消息。但是最早的聊天消息首先出现,我必须向下滚动才能看到最新的消息。我想在页面加载后结束ng-repeat即最新的聊天和向上滚动,如果需要看到旧的聊天,就像在任何其他mesaaging应用程序。

HTML:

<div class="panel-body">
            <ul class="chat">
                <li ng-repeat="msg in msgListing" ng- class="msg.senderid==senderidvalue ? 'left clearfix sender' : 'right clearfix reciever'">
                        <div class="header">
                            <strong ng-class="msg.senderid==senderidvalue ? 'pull-left primary-font' : 'pull-right primary-font'">
                                <p ng-if="msg.senderid == senderidvalue">{{currentusername}}</p>
                                <p ng-if="msg.senderid != senderidvalue">{{recievername}}</p>
                                </strong> <small ng-class="msg.senderid==senderidvalue ? 'pull-right text-muted' : 'pull-left text-muted'">
                                <span class="glyphicon glyphicon-time"></span>{{msg.senton}}</small>
                        </div>

                        <p class="chat-text">
                            {{msg.messagetext}}
                        </p>    
                </li>
            </ul>
        </div>

Sample Output Image

2 个答案:

答案 0 :(得分:2)

添加值时使用scrollHeight

&#13;
&#13;
 
var scroller = document.getElementById("autoscroll");
      scroller.scrollTop = scroller.scrollHeight;
    }, 0, false);
&#13;
&#13;
&#13;

答案 1 :(得分:0)

使用ng-repeat和orderBy就像这里

<tr ng-repeat="friend in friends | orderBy:predicate:reverse">

您找到了文档enter link description here