ionic-framework: [v2] Ion-infinite-scroll error when leaving page
Just wanted to bring to your attention the following error when leaving a page that uses ion-infinite-scroll
:
EXCEPTION: TypeError: Cannot read property 'removeEventListener' of null
<ion-infinite-scroll (infinite)="doInfiniteScroll($event)">
<ion-infinite-scroll-content></ion-infinite-scroll-content>
</ion-infinite-scroll>
Reproduce by:
- Add the above code to a list page
- Navigate to that page
- Navigate to another page
- View console output
My system information:
Cordova CLI: 6.0.0
Ionic Version: 2.0.0-beta.2
Ionic CLI Version: 2.0.0-beta.19
Ionic App Lib Version: 2.0.0-beta.9
ios-deploy version: 1.8.5
ios-sim version: 5.0.6
OS: Mac OS X El Capitan
Node Version: v4.3.1
Xcode version: Xcode 7.2.1 Build version 7C1002
Not positive, but this could also be related to this similar issue.
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 7
- Comments: 21 (8 by maintainers)
Commits related to this issue
- fix(ion-infinite-scroll): Fix error leaving page This fix [5760](https://github.com/driftyco/ionic/issues/5760) — committed to trongrg/ionic by trongrg 8 years ago
@warner-pinz You could apply the fix directly in your project:
node_modules/ionic-angular/components/content/content.js
_this.scrollElement.removeEventListener(type, handler);
if (!_this.scrollElement) { return; }
I can confirm that the bug still exists in
beta.3
. As @jboothe mentioned, the exception is thrown when leaving the page that contains<ion-infinite-scroll>
component. Also, as pointed out by the others, the bug affects also the<ion-refresher>
component.Steps to reproduce:
Other information: I did some debugging and realized that the exception is thrown when the
InfiniteScroll
component tries to remove an event-handler after the element to which the handler is attached is already removed byContent.ngOnDestroy()
. The removal procedure is triggered byInfiniteScroll.ngOnDestroy()
, which for some reason is called afterContent.ngOnDestroy()
(InfiniteScroll’s host component) has been already completed. A null-check in the function returned byContent._addListener()
should fix the problem but I’m not sure if the remaining handler will be removed automatically. In theory when the component’sngOnDestroy()
is called before the one of its host component has completed, everything should work fine, but I have no idea why in practice it’s called after. I guess that it might be either async by design (without a guarantee which is called first) or due to a bug in Angular 2.Which Ionic Version? 2.x
Run
ionic info
from terminal/cmd prompt:Yep, I have the same problem.