Im building a phonegap app and have implemented angularjs in it. The app uses my jquery plugin for page transitions, so each page is loaded using ajax. Each HTML page has its own controller in a separate JS file. So the logic is basically:
- Load all JS files (controllers) at the index page.
Run my page transition plugin and change page. When done do a callback and run this code to trigger the angularjs controller:
$(document).on('pageready', function(e, input) { $(input.page).attr('ng-init','init('+JSON.stringify(input.params)+')'); angular.bootstrap($(input.page), []); });
- The code above will trigger the controller for the newly loaded page
This works great. My problem is that I have 1 page that has scrollable content. I cache this list and when the app user visit the page a second time I want to scroll to the position the user was on last in the list. I solved this using:
$scope.$watch('$last',function(){
$scope.$apply();
$("#mylist").scrollTop($scope.input.scroll);
});
but this throws an error: ERROR: Error: [$rootScope:inprog]
I've tried a lot of different things to get rid of this error but the above code is the only thing that I have manged to use to set the scroll position:
- I tried not using apply, but then the scroll is never done.
- I've tried using directives, but due to my setup these are not called, only the controller is triggered on page change
- I tried angular.element(document).ready(function () { --- No effect
- I tried $scope.$on('$viewContentLoaded', function() { --- No effect
- I tried $scope.$watch('$viewContentLoaded', function() { --- No effect
I probably tried more but without luck. Any ideas?
Thanks.