uniprank / ngx-scrollspy Goto Github PK
View Code? Open in Web Editor NEWAngular Scroll Spy Service with events
License: MIT License
Angular Scroll Spy Service with events
License: MIT License
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!
import { NgxScrollspyModule } from '@uniprank/ngx-scrollspy';
imports: [
// other imports
...
NgxScrollspyModule.forRoot()
]
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>
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();
}
}
}
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 ?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.