question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Layout] NbLayoutScrollService code example request

See original GitHub issue

Issue type

I’m submitting a … (check one with “x”)

  • feature request

Issue description

Current behavior: NbLayoutScrollService documentation is really dry.

Expected behavior: Some code examples would be much appreciated.

Steps to reproduce:

Related code: I attempted to figure out how it work, but for a newbie it’s a bit too much without a guidance. Here is what i thought should work.

ngAfterViewChecked(): void {
    function getOffset(el) {
      const rect = el.getBoundingClientRect();
      return {
        left: rect.left + window.scrollX,
        top: rect.top + window.scrollY
      };
    }
    try {
      const pageElement = document.getElementById(this.fragment);
      if (pageElement) {
        this.scrollService.scrollTo(getOffset(pageElement).left, getOffset(pageElement).top);
        this.fragment = '';
      }
    } catch (e) { }
  }

Angular, Nebular

"@angular/core": "6.0.3"
"@nebular/auth": "^2.0.0-rc.10"
"@nebular/security": "^2.0.0-rc.10"
"@nebular/theme": "^2.0.0-rc.10"

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:2
  • Comments:5

github_iconTop GitHub Comments

1reaction
denisobrienirlcommented, Aug 13, 2018

Hi @nnixaa , Maybe i’m conceptually wrong here. My understanding is that this service allows for a page scroll similar to scrollIntoView() function. I’m looking for an alternative to this function as its following usage doesn’t work in Safari:

document.querySelector('#' + this.fragment).scrollIntoView({ behavior: 'smooth', block: 'start', inline: 'nearest' });

So, i was looking for some example of NbLayoutScrollService usage, just to see how the service should be used. With the code i provided in the original post i get no errors, just no scroll happens.

Hope this makes sense. Let me know if you need more info.

Cheers,

0reactions
RoWEN-FCUBcommented, Jan 18, 2021

This worked for me:

this.nbLayoutScrollService.onScroll().subscribe(r => {
      this.nbLayoutScrollService.getPosition().subscribe(p => console.log(p));
    });
Read more comments on GitHub >

github_iconTop Results From Across the Web

Nebular - LayoutScrollService - GitHub Pages
NbLayoutScrollService. Layout scroll service. Provides information about current scroll position, as well as methods to update position of the scroll.
Read more >
Getting started with Nebular for Angular
Open src\app\app.component.html and insert the following code. <nb-layout> < ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found