joelmukuthu / angular-snapscroll

Vertical scroll-and-snap functionality in angular
http://joelmukuthu.github.io/angular-snapscroll/
MIT License
56 stars 18 forks source link

compositeIndex is undefined #44

Open heck4 opened 7 years ago

heck4 commented 7 years ago

I had a situation where I was loading the view, and the div containing the snapscroll was initially not shown. The user clicks on a tab in the page, and then the div is shown. When I attempt to use the wheel to scroll, it threw an error on line 453:

var snapIndex = scope.compositeIndex[0];

compositeIndex was undefined.

When I loaded the view and had the div with angular scroll shown on init... it triggered a call to snapIndexChanged which initialized the scope's compositeIndex on line 348:

scope.compositeIndex = [current, 0];

So it seems like you're using a Changed event to do some initialization. My workaround was this ng-init hack:

<div class="element-template-bars" snapscroll="" snap-index="0" ng-init="$$childHead.compositeIndex= [0, 0];" snap-duration="300" scroll-delay="false" enable-arrow-keys="true" prevent-double-snap-delay="150">

Thanks.

joelmukuthu commented 7 years ago

Hi, thanks for this. I think it's the same issue that was posted here #35, which I still haven't managed to reproduce :/

Is it possible to create a jsfiddle with some minimal code that can reproduce the issue? Even though I can probably fix it by initializing the compositeIndex to [0, 0] (neat dirty hack btw :)), I'd like to add a test for it so that it doesn't end up regressing later, for instance when I expose the compositeIndex as an attributre binding.

heck4 commented 7 years ago

I haven't made a jsFiddle before, but I figured it was time to learn. I spent a couple hours on this, but I wasn't able to reproduce the issue. And I can't give you my project unfortunately.

This is as far as I got: https://jsfiddle.net/casey_plummer/e69ze2a5/

However, the footer works no matter if its shown later, and doesn't raise the error.

I have a feeling that the issue is related to ui-router. In my project I'm changing url/route state based user navigation clicks (all on the same page/controller). In most cases, I'm using $state.go to the same state, but different params. And I'm using the options where notify is false, and reload is false.

https://ui-router.github.io/ng1/docs/0.3.1/index.html#/api/ui.router.state.$state

So I can basically update the state and the url to match what the user clicked, but I don't reload the controller at all, and its very fast. In this scenario it might not be raising the same load events. But this is just a guess.

Good luck, I can't spend any more time on troubleshooting this.

joelmukuthu commented 7 years ago

Thank you for taking the time and the extra info, much appreciated :) I'll keep this open while I try to figure it out

heck4 commented 7 years ago

Before I leave this topic, I had my browser breakpoints still in place, and here's screenshots of them.

The error in the console: snapscroll_error

The breakpoint on the error: snapscroll_error_breakpoint

How scope.compositeIndex is normally initialized. The requestLoaded event is triggering a digest. snapscroll_init