【问题标题】:Scroll to bottom of page after get request AngularJs获取请求AngularJs后滚动到页面底部
【发布时间】:2014-02-28 22:55:29
【问题描述】:

我熟悉使用类似的东西:

$scope.gotoBottom = function(){
    $location.hash('bottom');
    $anchorScroll();
}

这有效.. 但是我看到的是在检索 ng-repeat 中使用的数据并尝试在该数据进入时调整大小时出现问题。

示例(在控制器中):

users.get({userList:$routeParams.conversationId}, function(data){
        $scope.userList = data;
        $scope.gotoBottom();
})

gotoBottom 方法正在快速触发,而 ng-repeat 正在查看 $scope.userList 并基于此构建它的表。

我希望能够在重新制作该列表后(或在修改它时)切换 gotoBottom。有没有更好的方法来实现这一点?

谢谢!

【问题讨论】:

    标签: javascript angularjs


    【解决方案1】:

    你也可以在页面加载后运行滚动底部

    angular.element($window).bind('load', 
      function() {
      var element = document.getElementById("messages-list").lastElementChild;
        element.id = "bottom";
        /*-------------*/
        $location.hash('bottom');
        $anchorScroll();      
    }
    

    【讨论】:

      【解决方案2】:

      当 AngularJs 变量发生变化时,您可以使用 $watch listener 触发 gotoBotton。

      $scope.ActivityList = new Array();
      
      $scope.$watch("ActivityList", function () {
          $scope.$evalAsync(function () {
              $scope.DoSomething();
          });
      }, true);
      
      $scope.DoSomething = function () {
          $(function () {
              //$scope.gotoBottom();
          });
      };
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-05-14
        • 2012-07-27
        • 1970-01-01
        • 1970-01-01
        • 2010-12-25
        • 1970-01-01
        相关资源
        最近更新 更多