JonnyBGod / ngx-scrollspy

Angular ScrollSpy Service

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Spying on an element doesn't resolve.

cvlos opened this issue · comments

Hi. I need some help. I am trying to spy on an element but the observable never resolves. This is my code:

import { Component, ViewChild, ElementRef, AfterViewInit } from '@angular/core';
import { ScrollSpyModule, ScrollSpyService, ScrollSpyDirective } from 'ngx-scrollspy';

@Component({
	selector: 'app-root',
	template: `
		<div style="background-color: red;height: 1400px; width: 500px;"></div>
		<div  style="max-height: 1000px; overflow: scroll; background-color: blue;">
			<div scrollSpyElement="test" style="height: 500px;"></div>
		</div>
	`
})
export class AppComponent implements AfterViewInit{
	@ViewChild('secondarySidebar') sidebar: ElementRef;

	constructor(private scrollSpyService: ScrollSpyService) {}

	ngAfterViewInit() {
		console.log(this.scrollSpyService.getObservable('test'), 'hoho**********');
		this.scrollSpyService.getObservable('test').subscribe((e: any) => {
			console.log('ScrollSpy::window: ', e, 'Window');
		});
	}
}

Any ideas?

try:

<div scrollSpyElement="test" style="max-height: 1000px; overflow: scroll; background-color: blue;">
   <div style="height: 500px;"></div>
</div>

Nothing. This:

subscribe((e: any) => {
			console.log('ScrollSpy::window: ', e, 'Window');
		});

never gets resolve therefore the console.log message never gets printed

This is what I get in the first console.log
screen shot 2017-05-04 at 11 03 01 pm

Thanks for your fast response BTW.

I added ScrollSpyModule to both app.module and my home.module and it works. I will close the issue