Angular-2-Page-Slider icon indicating copy to clipboard operation
Angular-2-Page-Slider copied to clipboard

Cannot read property 'pageCountChange' of undefined

Open rupakshukla opened this issue 8 years ago • 5 comments

// Get the page renderer loop and keep its size up to date @ContentChild(KBPagesRendererDirective) renderer : KBPagesRendererDirective; ngOnInit(){ this.renderer.pageCountChange.subscribe((count)=>{ this.pageCountChange.emit(count); });

    this.Resize();
    this.renderer.Resize(this.pageWidth, this.pageHeight);
    window.addEventListener("resize", ()=>{
        this.Resize();
        this.renderer.Resize(this.pageWidth, this.pageHeight);
        this.pageSizeChange.emit([this.pageWidth, this.pageHeight]);
    });
}

It is giving error Cannot read property 'pageCountChange' of undefined which seems renderer is not getting defined, what exactly is not working in my case. Which is defined in this @ContentChild(KBPagesRendererDirective) renderer : KBPagesRendererDirective;

Angular Version - 2.0.0-rc.1

rupakshukla avatar Jul 21 '16 18:07 rupakshukla

Does your template have a *kbPages="let page of pages" directive in it?

I should add an extra check, instead of just assuming it exists. I do in some other places but apparently missed ngOnInit. Will fix.

KeatonTech avatar Jul 21 '16 18:07 KeatonTech

Yes i have this in my template *kbPages="let page of pages"

still it is not working.

Only difference in our case is that we are not bootstraping this component in same component. I have a app component in which i import this slider component and i bootstrap the app component.

rupakshukla avatar Jul 21 '16 19:07 rupakshukla

Yeah, that is the normal use case (See /examples/hero/app.ts). Are you importing both KBPagesRendererDirective and KBPageSliderComponent into your app component as directives? Or, I guess more broadly, are there any errors in the web inspector?

KeatonTech avatar Jul 21 '16 19:07 KeatonTech

yes, i am importing KBPagesRendererDirective and KBPageSliderComponent in my component as directives. and have also followed your example ( /examples/hero/app.ts). But Still getting the error

Cannot read property 'pageCountChange' of undefined

rupakshukla avatar Jul 21 '16 19:07 rupakshukla

Hmm, that is very odd. Is there anything you've done differently from the example that I could test to see if I can reproduce the error?

KeatonTech avatar Jul 21 '16 20:07 KeatonTech