ionic-framework icon indicating copy to clipboard operation
ionic-framework copied to clipboard

Scroll position after changing view - AngularJS

Open JonathanHindi opened this issue 12 years ago • 9 comments

I notice an issue it may happens specially because the way I include my views.

I have a sideMenu with some links when tapping on of the links it goes to a router that load a template file using the normal $routeProvider.when('/link', {templateUrl: '/templates/link.html', controller: 'LinkCtrl'}); inside an <ng-view></ng-view> directive.

Everything work fines expect if for example I accessed link1 and scrolled down then opened the side menu and tapped link2 the view opened scrolled a little bit, I think it happens because the scroll plugin store the current position on the ng-view element itself.

I thought of current workaround but it doesn't work as expected. Add scroll="false" attribute on <ng-view> and then inside the template file find the first tag e.g <div> ad scroll="true".

You did a great job with the new scroll implementation it works better, and I hope you would be able to fix any related bugs.

JonathanHindi avatar Dec 09 '13 14:12 JonathanHindi

I have similar problems. When I scroll down to the third or fourth card and click them, go to the card page(change view), the position is not top, I have to scroll up to see then content

benmliang avatar Dec 09 '13 20:12 benmliang

I had a similar problem. Is there a way we could add a scrollToTop function to the scroller?

lingz avatar Dec 13 '13 16:12 lingz

I added the following to listen to Angular $viewContentLoader event and then using the new ScrollDelegate service in the main controller.

/* When View Content Loaded */
  $scope.$on('$viewContentLoaded', function() {

    // Scroll to Top
    // Set ture for animation which isn't needed in my case
    ScrollDelegate.scrollTop(false);

  });

Don't forget you need to inject the ScrollDelegate before you use it in your controller, another way could be by firing the scroll.scrollTop event.

$scope.$broadcast('scroll.scrollTop')

Mentioned by @mlynch on the forums here

But I think it make sense that the framework do it on itself.

JonathanHindi avatar Jan 03 '14 20:01 JonathanHindi

Hi @JonathanHindi, sorry for the late response.

Is this bug still valid in v0.9.23?

ajoslin avatar Feb 07 '14 18:02 ajoslin

No It was fixed a while ago. So I will close.

JonathanHindi avatar Feb 07 '14 18:02 JonathanHindi

@JonathanHindi

I added the following to listen to Angular $viewContentLoader

it doesn't work when all templates are pre-cached in JS. And this is a good practice, so please consider to find some more universal solution.

e-oz avatar Apr 16 '15 19:04 e-oz

I'm suffering this glitch right now.

Until now i've been using next to avoid the scroll problem:

  $rootScope.$on("$viewContentLoaded", function () {
    $anchorScroll();
  });

But this makes scroll is always on top, which is a little bit annoying when user wants to go back and keep surfing from the point he was.

rubenjimenez avatar Apr 20 '15 14:04 rubenjimenez

@rubenjimenez try attribute overflow-scroll="true" - it solved my issue (and not one).

e-oz avatar Apr 20 '15 20:04 e-oz

@rubenjimenez Would you be able to explain where exactly I would put that code, and how I would insert it into the existing code? Thanks in advance for any help you can provide.

saltmktg avatar May 04 '15 19:05 saltmktg