Hi I have a factory that GETs data from a backend. This data is then processed with a controller (as seen below) and injected in the web page with ng-repeat. Due to asynchronous nature of the system, I have troubles when I try to manipulate window. For example I need to use window.scrollTo function but only AFTER data was completely processed and displayed on screen with ng-repeat.
As you can see here, I tried to use a promise early in the controller. But it doesn't work: window.scrollTo is always processed before data has finished being processed on screen. I guess what I need is a way to actually force the data process to be completed and only then process the window.scrollTo function but I don't see how.
    .controller('myCtrl',
    function ($scope, prosFactory, fieldValues, $q ) {
        $scope.listpros = function() {
            prosFactory.getPros()
                .success(function(data, status) {
                    var defer = $q.defer();
                    defer.promise
                        .then(function () {
                          $scope.prosItems = data;  // pass data to ng repeat first                           
                            })
                        .then(function () {
                            $window.scrollTo(0, 66); // then scroll 
                          });
                    defer.resolve();   
                }).error(function(data, status) {
                    alert("error");
                }
            );
        };
I tried with a 2000 timeout on scrollTo function, but due to variation in internet speed, it sometimes delay the scroll to much, or sometime isn't enough.
 
     
     
    