aliok / ion-affix

Affix elements for Ionic framework
MIT License
83 stars 29 forks source link

Scroll listener is not removed if element is destroyed #1

Closed macecyri closed 9 years ago

macecyri commented 9 years ago

Thanks for this useful plugin!

I used the ion-affix directive on elements of a dynamic array (updated with ng-repeat) and the scroll listener (line 168: angular.element($ionicScroll.element).on('scroll', ....) is created each time my array is updated, resulting in strange behaviour because the scroll function is called twice after one update, three times after 2 updates etc...

I managed to resolve this problem by adding the folowing code to the directive

$scope.$on("$destroy",function() {
                angular.element($ionicScroll.element).off('scroll');
            });

Could you add this snippet or a to the next release of the plugin? Or maybe you think there is a more elegant way to resolve this problem

Thanks again for your work

aliok commented 9 years ago

Thanks for reporting the problem and also suggesting the solution. I've added the fix you suggested.

aliok commented 9 years ago

Gonna release 1.0.1 soon with this fix.

aliok commented 9 years ago

Released 1.0.1.