I have sample code posted here AngularJsScrollPersisterDemo
The code works for me when I host the files in a website. The magic is really done in the directive and the service.
directive:
(function (angular) {
"use strict";
angular.module("ScrollPersisterApp").directive("scrollPersister", ["scrollPersisterService", scrollPersister]);
function scrollPersister(scrollPersisterService) {
return {
restrict: "A",
link: function (scope, element, attributes) {
element[0].scrollTop = scrollPersisterService.GetScrollTop();
scope.$on('$destroy', function () {
scrollPersisterService.SetScrollTop(element[0].scrollTop);
});
}
};
}
})(angular);
The directive sets the scrollTop of the div via the injected scrollPersisterService when it is destroyed, such as by a $route.reload(). Upon reload, the directive reads the scrollTop value from the scrollPersisterService and sets it as the scrollTop of the div via JavaScript.
See my github repository I linked for the full example. I have tested this code in the latest version of Chrome and it works great.