Yeny Firvida
Yeny Firvida

Reputation: 13

onsen ui problems with carousel

I have the following carousel with some inside but when i try to use in my controller mycarousel.getActiveCarouselItemIndex() the app says Uncaught ReferenceError: mycarousel is not defined

Please help me, Im new in onsen. Thanks.

Upvotes: 0

Views: 651

Answers (1)

Andreas Argelius
Andreas Argelius

Reputation: 3614

When you define the carousel you can assign it to a variable by using

<ons-carousel var="mycarousel">
  ...
</ons-carousel>

It will be attached to the variabled window.mycarousel.

Another way to get the object is to listen for the ons-carousel:init DOM event:

document.addEventListener('ons-carousel:init', function(e) {
  var mycarousel = e.component;
});

Upvotes: 1

Related Questions