Git Product home page Git Product logo

ngx-scrollspy's People

Contributors

aboutandre avatar denfie avatar dependabot[bot] avatar jeremielenoir avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

ngx-scrollspy's Issues

ScrollSpyService throws item with the id [...] already exists when routing

I am getting an error (as below) when I route to an another page and route back.
E.x. Routing from home page to contact page and returning back to home page

Any help is appreciated!

Version list

  • Angular v10.2.5
  • @uniprank/ngx-scrollspy: ^1.1.0

ERROR

image

app.module.ts

import { NgxScrollspyModule } from '@uniprank/ngx-scrollspy';

imports: [
// other imports
...
NgxScrollspyModule.forRoot()
]

home.component.html

Mobile horizontal navbar

<ul #mobileScroll>
    <li *ngIf="favCat?.length>0" (click)="func.scrollTo('c-0')" uniScrollItem="c-0" id="c-0-m">
      ...
    </li>
    <li *ngFor="let cat of categories" uniScrollItem="c-{{cat.id}}" id="c-{{cat.id}}-m (click)="func.scrollTo('c-' + cat.id)">
      ...
    </li>
</ul>

Desktop column for categories

<ul #navbarCategory>
  <li (click)="func.scrollTo('c-0')" *ngIf="favCat?.length>0" uniScrollItem="c-0" id="c-0-d">
    ...
  </li>
  <li *ngFor="let cat of categories" (click)="func.scrollTo('c-' + cat.id)" uniScrollItem="c-{{cat.id}}" id="c-{{cat.id}}-d">
    ...
  </li>
</ul>

Categories section

<section *ngIf="favCat?.length>0" uniScrollSpy="c-0">
    ...
</section>

<section *ngFor="let cat of categories" uniScrollSpy="c-{{cat.catId}}">
    ...
</section>

home.component.ts

import { ScrollSpyService, ScrollObjectInterface } from '@uniprank/ngx-scrollspy';

export class HomeComponent implements OnInit, AfterViewInit {
  private _subscription: Subscription;
  
  constructor(private _scrollSpyService: ScrollSpyService) { }
  
  ngAfterViewInit(): void {
    this._scrollSpyService.setOffset('window', 60);
    this._subscription = this._scrollSpyService.observe('window').subscribe((element: ScrollObjectInterface) => {
      if(element != null) {
        if(!this.func.preventScrollDetection) {
          var col = document.getElementById(element.id + '-m');
          if (col != null && this.mobileScroll.nativeElement != null) {
            this.mobileScroll.nativeElement.scrollLeft = (col.offsetLeft - (this.mobileScroll.nativeElement.offsetWidth / 2)) + (col.offsetWidth / 2);
          }
        }
      }
    });
  }
  
  ngOnDestroy() {
    if (this._subscription) {
      this._subscription.unsubscribe();
    }
  }
}

"getObservable" only exists in the README and not in the actual codebase

i get that this was portet from the JonnyBGod repository, but removed the most basic function, and still mentioning it in the documentation is just not good practice.

There now seems to be a "observe" function, but that is unable to locate any ids.

Could someone please update the README to reflect the actual usage of this NPM module ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.