Slick Carousel Angular - dynamic data loading

2019-09-06 18:36发布

问题:

When I use dynamic data to load the slick content, all the images come one below the other. I do not know why it happens. How do I resolve it? Looks like DOM needs data at initialization itself.

View:

<slick infinite=true slides-to-show=3 slides-to-scroll=3 settings="slickConfig" data="images">
    <div class="slick-item" ng-repeat="image in images">
        <div class="Slide-Id">
            <p class="slide-id">{{images.indexOf(image)+1}}/{{images.length}}</p>
        </div>
        <img src="{{image.url}}" height="100px" width="100px" />
    </div>
</slick>

// $scope.images = [ {
      //     url: '../../images/qr-code.png'
      //   }, {
      //     url: '../../images/qr-code.png'
      //   }, {
      //     url: '../../images/qr-code.png'
      //   }, {
      //     url: '../../images/qr-code.png'
      //   }, {
      //     url: '../../images/qr-code.png'
      //   }];
	  
	  //Hard coded values above loads properly as expected. But if it comes from server and then,
	  //it loads one below the other.
	  
	  
	  $scope.images = [];

        $scope.slickConfig = {
        //enabled: true,
        //autoplay: false,
        //draggable: true,  
       // method: {},
        arrows: false,
        //centerMode:true,
        //variableWidth: true,
        event: {
            beforeChange: function (event, slick, currentSlide, nextSlide) {
            },
            afterChange: function (event, slick, currentSlide, nextSlide) {
            }
        }
      };
	  
	  ...
				var data = ServiceFactory.getEventDetails();
				data
                 .then(onAuthenticated )
                 .catch(onRejectedRequest)
                 .finally(sessionServiceFinally);
				 
				 ....
				 
				 onAuthenticated(resp){
					 console.log("vm.tickets[i].images.." + resp[0].images);
					  $scope.images.push({url : resp[0].images});
					  $scope.images.push({url : resp[0].images});
					  $scope.images.push({url : resp[0].images});
					
				 }
	  

回答1:

I finally ended up using ng-if for this one to resolve :)