Scroll down after receiving AngularJs request

I am familiar with using something like:

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

and it works. But what I see is a problem when retrieving the data that is used in ng snooze and when trying to resize when that data arrives.

Example (in the controller):

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

The gotoBottom method starts quickly, while ng-repeat looks at $ scope.userList and creates a table based on this.

I want to be able to switch gotoBottom after this list has been redone (or when it has been modified). Is there a better way to achieve this?

Thank!

+3
source share
2 answers

You can use the $ watch listener to run gotoBotton when the AngularJs variable changes.

$scope.ActivityList = new Array();

$scope.$watch("ActivityList", function () {
    $scope.$evalAsync(function () {
        $scope.DoSomething();
    });
}, true);

$scope.DoSomething = function () {
    $(function () {
        //$scope.gotoBottom();
    });
};
+2

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

All Articles