sroze/ngInfiniteScroll — pull request #110 by piotrekpa (2014-07-21 15:01:26+00:00)
Title: Fixed bug: conflict of variable name (`$window`)

Hey

I have probably found an error concerning variable names.
It occurs when I'm using multiple instances of infinite scroll on one page.
Here is an example: http://jsfiddle.net/mgPXp/1/
When scrolling the page the first instance does not work.

In line 15 of the coffeeScript file (https://github.com/sroze/ngInfiniteScroll/blob/5ee6c882fd6a4d1cf2bae54e2f4fdaec19769697/src/infinite-scroll.coffee#L15) there is:

$window = angular.element($window)

In compiled code the variable `$window` is not declared in the `link` function (https://github.com/sroze/ngInfiniteScroll/blob/5ee6c882fd6a4d1cf2bae54e2f4fdaec19769697/build/ng-infinite-scroll.js#L19):

var changeContainer, checkWhenEnabled, container, handleInfiniteScrollContainer, handleInfiniteScrollDisabled, handleInfiniteScrollDistance, handleInfiniteScrollUseDocumentBottom, handler, immediateCheck, scrollDistance, scrollEnabled, throttle, useDocumentBottom;

and `$window = angular.element($window)` overrides `$window` (variable from dependency injection) across the whole directive. Now the condition from line 31 is `false` for first and `true` for second instance. (https://github.com/sroze/ngInfiniteScroll/blob/5ee6c882fd6a4d1cf2bae54e2f4fdaec19769697/src/infinite-scroll.coffee#L31)

if container == $window

My proposition is to change the name of variable in line 15.