JonnyBGod / ngx-scrollspy

Angular ScrollSpy Service
MIT License
94 stars 21 forks source link

Spying on an element doesn't resolve. #172

Closed cvlos closed 7 years ago

cvlos commented 7 years ago

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?

JonnyBGod commented 7 years ago

try:

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

Nothing. This:

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

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

cvlos commented 7 years ago

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.

cvlos commented 7 years ago

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