1

Angular 2 scroll event getting height is null.

[sample]: https://plnkr.co/edit/RZSQkd0nqolYv3NBvArG?p=preview
2
  • 1
    Why do you expect the attribute height to be set? What value do you expect to get? Commented Apr 14, 2016 at 8:22
  • nope i don't want to set height, i want get height of that div which has scroll, based on that i will write logic like infinite scroll logic. Commented Apr 14, 2016 at 9:56

1 Answer 1

1

Plunker example

Seems what you want is

  onScroll(){
    console.log('clientHeight: ' + this._el.clientHeight);
    console.log('offsetHeight: ' + this._el.offsetHeight);
  }

See also Get div height with plain JavaScript

getAttribute() reads attributes. Attributes are visible in the DOM. clientHeight is a property.

See also Properties and Attributes in HTML

Sign up to request clarification or add additional context in comments.

4 Comments

And how to implement, basic of infinite scroll. [plnkr.co/edit/RZSQkd0nqolYv3NBvArG?p=preview]
I haven't done an infinite scroll implementation myself yet. If you have more concrete questions I might be able to help but this is too broad. No idea where to start.
I just started learning angular 2. it will be helpful for beginners. i have query. i want to create a directive like scroller, that will bound to my component, my component has service logic to update the data which has scroller. but my scroller has only event of scrolling up and scrolling down, how do i bind component method to scroller directive scroll event.
Sorry, I think that's too broad for StackOverflow. Acually I don't even know what a scroller should do exactly. You might have a look at github.com/angular/material2 or github.com/justindujardin/ng2-material if they contain something like that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.