Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swiper Error Cannot read property 'length' of undefined #12791

Closed
blanchg opened this issue Aug 31, 2017 · 4 comments
Closed

Swiper Error Cannot read property 'length' of undefined #12791

blanchg opened this issue Aug 31, 2017 · 4 comments

Comments

@blanchg
Copy link

blanchg commented Aug 31, 2017

Ionic version: (check one with "x")
[x] 3.x

I'm submitting a ... (check one with "x")
[x] bug report

Current behavior:
Updating the data in an ion-list that contains an ion-slides causes a console error.

ERROR TypeError: Cannot read property 'length' of undefined
    at destroyLoop (swiper.ts:696)
    at Object.destroySwiper (swiper.ts:1002)
    at Slides.ngOnDestroy (slides.ts:1162)
    at callProviderLifecycles (query.ts:1)
    at callElementProvidersLifecycles (provider.ts:619)
    at callLifecycleHooksChildrenFirst (provider.ts:603)
    at destroyView (view.ts:642)
    at callWithDebugContext (services.ts:815)
    at Object.debugDestroyView [as destroyView] (services.ts:404)
    at ViewContainerRef_.remove (refs.ts:357)

Expected behavior:

Updating the data should not cause errors.

Steps to reproduce:

http://embed.plnkr.co/9RfxERbAm9PvR9DvJ5PJ/

Double click the update button and the error above will log to the console

Related code:
See Plnkr

Other information:

This could be fixed by testing for s._slides in ionic/src/components/slides/swiper/swiper.ts

function destroyLoop(s: Slides) {
  eachChild(s._wrapper, '.' + CLS.slide + '.' + CLS.slideDuplicate, ele => {
    ele.parentElement.removeChild(ele);
  });
  if (s._slides) {
    for (var i = 0; i < s._slides.length; i++) {
      s._slides[i].removeAttribute('data-swiper-slide-index');
    }
  }
}

Ionic info: (run ionic info from a terminal/cmd prompt and paste output below):

kensodemann added a commit that referenced this issue Sep 6, 2017
@kensodemann
Copy link
Member

Hello! Thank you for opening an issue with us!

A fix for this has been committed and will be in the next 3.6.x release.

Thank you for using Ionic

@kensodemann
Copy link
Member

We have created an ionic-angular@nightly with the fix for this issue included in preparation for a new release. I have tested it via the sample repo and it works for that particular case. If you would like to try this in your app you can use npm install ionic-angular@nightly

@blanchg
Copy link
Author

blanchg commented Sep 6, 2017 via email

@ionitron-bot
Copy link

ionitron-bot bot commented Sep 2, 2018

Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out.

@ionitron-bot ionitron-bot bot locked and limited conversation to collaborators Sep 2, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants