Skip to content
This repository has been archived by the owner on May 5, 2021. It is now read-only.

Not working with AngularJS #64

Open
salarelv opened this issue Mar 16, 2015 · 6 comments
Open

Not working with AngularJS #64

salarelv opened this issue Mar 16, 2015 · 6 comments

Comments

@salarelv
Copy link

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
Copy link

Any headway here? I am also stuck here.

@boyum
Copy link

boyum commented Mar 18, 2016

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
Copy link

Same problem here. Any solutions?

@boyum
Copy link

boyum commented May 26, 2016

What have you tried?

@dmiranda2791
Copy link

dmiranda2791 commented May 26, 2016

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

@SirFart4lot
Copy link

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

setTimeout(initSlider);

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants