Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/84.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript autoscroll angularjs不';好像不行_Javascript_Jquery_Angularjs_Angularjs Directive_Angularjs Ng Repeat - Fatal编程技术网

Javascript autoscroll angularjs不';好像不行

Javascript autoscroll angularjs不';好像不行,javascript,jquery,angularjs,angularjs-directive,angularjs-ng-repeat,Javascript,Jquery,Angularjs,Angularjs Directive,Angularjs Ng Repeat,嗨,我正在用angularjs构建一个聊天应用程序,我希望聊天框能自动向下滚动。我正在使用这个例子,我在一个指令中加入了这个例子: 它的工作原理是,但当我使用它与ng重复它不工作 html文件 <ul id="chat" style="height:300px; overflow:auto" scroll-if> <li data-ng-repeat="messageinfo in messages" >

嗨,我正在用angularjs构建一个聊天应用程序,我希望聊天框能自动向下滚动。我正在使用这个例子,我在一个指令中加入了这个例子:

它的工作原理是,但当我使用它与ng重复它不工作

html文件

     <ul  id="chat" style="height:300px; overflow:auto" scroll-if>

            <li data-ng-repeat="messageinfo in messages" > 

                <div class="message-date">
                    {{messageinfo[0]}}
                </div>

            </li>

        </ul>

有什么帮助吗?当您调用代码时,感谢您:

var chat_height = $('#chat').outerHeight();
console.log(chat_height);
$('#chat').scrollTop(chat_height);
您的ng repeat未运行并完成其渲染,但返回的
outerHeight
不正确

ng repeat
完成时,必须运行代码。为此,您可以定义另一个指令:

.directive('scrollItem',function(){
    return{
    restrict: "A",
    link: function(scope, element, attributes) {
        if (scope.$last){ // If this is the last item, trigger an event
           scope.$emit("Finished");
       }
    }
   }
});
使用它:

<li data-ng-repeat="messageinfo in messages" scroll-item>

调用代码时:

var chat_height = $('#chat').outerHeight();
console.log(chat_height);
$('#chat').scrollTop(chat_height);
您的ng repeat未运行并完成其渲染,但返回的
outerHeight
不正确

ng repeat
完成时,必须运行代码。为此,您可以定义另一个指令:

.directive('scrollItem',function(){
    return{
    restrict: "A",
    link: function(scope, element, attributes) {
        if (scope.$last){ // If this is the last item, trigger an event
           scope.$emit("Finished");
       }
    }
   }
});
使用它:

<li data-ng-repeat="messageinfo in messages" scroll-item>