Codeinwp / Ideal-Image-Slider-JS

Quite simply the ideal Image Slider in vanilla JS.
http://idealimageslider.com
GNU General Public License v3.0
1.57k stars 159 forks source link

Not working with AngularJS #64

Open salarelv opened 9 years ago

salarelv commented 9 years ago

I have dynamic list of images created by a AngularJS controller. After calling var slider = new IdealImageSlider.Slider('#slider'); the will be cleared and no img element is set. If I remove the constructor all images show up fine.

anupamme commented 8 years ago

Any headway here? I am also stuck here.

boyum commented 8 years ago

The problem might be that you call var slider = new IdealImageSlider.Slider('#slider'); before the list has been added to the DOM. I assume you're using ngRepeat to create the elements. Use the $viewContentLoaded-event to run the slider-code when the ngRepeat has done its thing.

HTML:

<div id="slider">
  <img ng-repeat="slide in sliderCtrl.slides" src="{{slide.src}}" alt="{{slide.alt}}" />
</div>

JS:

.controller('SliderController', SliderController);

function SliderController() {
  var vm = this;
  activate();

 function activate() {
    $scope.$on('$viewContentLoaded', function() {
     $timeout(function() {
        var slider = new IdealImageSlider.Slider({
          selector: '#slider',
           ...
          });
         slider.start();
       });
    });
  } 
}
dmiranda2791 commented 8 years ago

Same problem here. Any solutions?

boyum commented 8 years ago

What have you tried?

dmiranda2791 commented 8 years ago

I tried listening to the viewContentLoaded event but it didn't work.

SirFart4lot commented 7 years ago

Simply running inside a timeout solved it for me...

setTimeout(initSlider);