Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ionic scrollTop "Cannot read property 'scrollTo' of null" (still exists in 1.0.0-rc.1)

This bug was referred to here: in ionic changing route causes "TypeError: Cannot read property 'scrollTo' of null"

The answer says that this bug was fixed in beta-13, but I'm using 1.0.0-rc.1 and the bug still appears.

In my case, it the error is showing when navigating back to a page that uses $ionicScrollDelegate.scrollTop()

Is anyone else getting this error after updating to rc.1?

EDIT: I find that if I do not call $ionicScrollDelegate.scrollTop() automatically when my view loads, the error does not come up. Should I be calling scrollTop() within a specific Ionic event that waits for the right time?

like image 588
Rastographics Avatar asked Mar 25 '15 04:03

Rastographics


3 Answers

Had the same problem, even with v1.0.0 "uranium-unicorn".

Wrapping the scroll call into a $timeout helped - this is what it looks like in my code:

   $timeout(function() {
                $ionicScrollDelegate.scrollTo(scrollPosition.left, scrollPosition.top);
            }, 0);
like image 116
Rautec Avatar answered Sep 28 '22 08:09

Rautec


You can just put it in

$ionicPlatform.ready(function () {
    $ionicScrollDelegate.scrollTop();
})
like image 38
Amine Sa Avatar answered Sep 28 '22 09:09

Amine Sa


Im late to this but was getting the same error but by calling the scroll top element with:

$ionicScrollDelegate.scrollTop();

but rather:

var scrollTop = e.detail.scrollTop;

and fixed my by using the following:

var scrollTop = $ionicScrollDelegate.getScrollPosition().top;

Im also using js scrolling as it seems to work better with the scrolla-sista plugin so I have the following in my config block at the start of my app

  $ionicConfigProvider.scrolling.jsScrolling(true);

where their docs state:

Whether to use JS or Native scrolling. Defaults to native scrolling. Setting this to true has the same effect as setting each ion-content to have overflow-scroll='false'.

I hope this helps someone

like image 43
garrettmac Avatar answered Sep 28 '22 08:09

garrettmac