Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UI bootstrap carousel first slide doesn't show then crashes at last slide

I am trying to implement ui-bootstraps carousel but when the page loads the first image doesn't show but the controls and indicators do.

Then, when the second image shows, I can use the controls to go back to the first image and it will show fine. I can use the controls to get to the last slide or let it slide automatically but when I get to the last slide the carousel stops working and gives the error "Cannot read property 'slide' of undefined" which points to line 576 of the ui-bootstrap-tpls.js file.

Not sure what I'm doing wrong as this seems pretty simple to implement, here is my code and here is a link to a site with a live example of whats going on .

Example Site

View

<div class="slider">
  <uib-carousel active="active" interval="3000">
    <uib-slide ng-repeat="slide in home.slides track by slide.id" index="slide.id">
      <img class="img-responsive" ng-src="{{slide.img}}" alt="{{slide.alt}}">
    </uib-slide>
  </uib-carousel>
</div>

Controller

.controller('HomeCtrl', function() {
  var vm = this;

  vm.slides = [
    {id: "1", img: 'img/slider/customer.jpg', alt: 'customers'},
    {id: "2", img: 'img/slider/juices.jpg', alt: 'e-juice'},
    {id: "3", img: 'img/slider/lineup.jpg', alt: 'vaporizers'},
    {id: "4", img: 'img/slider/vapeon.jpg', alt: 'vape on'}
  ];
};

*edit

I tried out the regular bootstrap carousel and it works fine. I can use it instead to solve the problem but I'd rather figure out what I'm doing wrong with the ui-bootstrap carousel.

like image 314
Grant Jordan Avatar asked May 02 '16 14:05

Grant Jordan


2 Answers

I was receiving a similar error, it was saying: "TypeError: Cannot read property 'slide' of undefined".

I followed one of the comments here and changed:

index="slide.id"

for

index="$index"

And that fixed the problem. I noticed this did not have an answer so I wanted to submit this.

like image 122
V.Hughes Avatar answered Nov 14 '22 05:11

V.Hughes


the problem is in ids - the first id of your picture should be 0, and you will be just fine

like image 32
vvn050 Avatar answered Nov 14 '22 05:11

vvn050