Can't call methods on Slider

I’m attempting to call slider.slideTo on the Slider component, and it fails with Cannot read property 'slideTo' of undefined. The Slider component is referenced correctly, because I can print it:

`Slides {elementRef: ElementRef, _id: "i20", ionWillChange: EventEmitter, ionDidChange: EventEmitter, ionDrag: EventEmitter…}`

but it looks like the internal slider reference (slides.js:583) is undefined.

I’m using ionic-angular 2.0.0-beta.10

  @ViewChild(Slides) slider: Slides;
  ...
  ngAfterViewInit() {
     console.log(this.slider); // displays slider

     this.slider.slideTo(1);
}

This no longer seems to be an issue, unsure what fixed it.

I too get this error. Some resolution?

Hi @emirliz, after seeing this a couple times, the internal slider reference never became null again. However, I need need to set the slideOptions in the Slider because the slideTo method didn’t do anything:

slideOptions = {
  direction: 'horizontal',
  // FIXME The height should not be hard-coded here
  // The correct behavior is that slider.container[0].clientWidth should be set
  width: 425
};

As I say in the comment, the slider.container[0].clientWidth variable is not being set; it should be set by the browser, but for some reason this doesn’t occur … I suspect the Slider is being initialized before the javascript engine could set this field.

I don’t know that this will fix your problem, but perhaps will give you a direction to look into.

1 Like

Thank you! I need selecting a slide when open the page.