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

scope.whenNotVisible is not a function #1

Closed
jagged3dge opened this issue Jul 30, 2015 · 5 comments
Closed

scope.whenNotVisible is not a function #1

jagged3dge opened this issue Jul 30, 2015 · 5 comments

Comments

@jagged3dge
Copy link

Problem: scope.whenNotVisible is not a function is thrown if the when-not-visible attribute is omitted in the template markup.

Thank you for making this lovely gem of a directive. Much lighter than in-view too :)
However, here's a snag that I hit. I have this markup:

<div class="community-posts" when-visible="loadPosts">
  <!-- community post content here -->
</div>

and here's my relevant code from the controller:

var loadPosts = function ($el) {
  var posts = [{id: 1, content: 'foo bar'}, {id: 2, content: 'bar foo'}];
  return posts;
};
$scope.loadPosts = loadPosts;

But when I view the page, it throws this error in the console:

TypeError: scope.whenNotVisible is not a function

This line is where the debugger points to:

determineWhereElementIsInViewport(el, viewportHeight,
            scope.whenVisible(), scope.whenNotVisible(), delayPercent, scope);

This most likely has to do with how the reference to the whenVisible and whenNotVisible functions are passed around in the directive. If the when-not-visible attribute is omitted, scope.whenNotVisible itself remains undefined causing this error being thrown.

@rpocklin
Copy link
Owner

Thanks really appreciate the effort for this feedback, i'll take a look in detail in the next day or so.

@rpocklin
Copy link
Owner

rpocklin commented Aug 3, 2015

I've fixed up the detection of these functions and updated ngdocs and bumped to v0.9.2 - here's the commit a3c190b - thanks for finding this.

@rpocklin rpocklin closed this as completed Aug 3, 2015
@jagged3dge
Copy link
Author

Thanks for the quick update @rpocklin

However, with the new 0.9.3 release, the issue is back, albeit at a different line. The attribute when-not-visible is not optional any more.
If I do not specify the when-not-visible attribute at all, it throws an error:

Uncaught TypeError: whenNotVisibleFn is not a function

Seems like a scoping issue. Instead of it defaulting to angular.noop, the value of whenNotVisibleFn returns undefined.

This is the line the debugger errors at:

        else if (!($el.data('hidden')) && (panelBottom < 0 || panelTop > viewportHeight)) {
          whenNotVisibleFn($el, scope); // <= this line no. 63
          $el.data('hidden', true);
        }

@rpocklin
Copy link
Owner

Apologies - see v0.9.4 for the fix. For real this time 👍

@jagged3dge
Copy link
Author

Lovely little fix. Thanks for the quick update!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants