In my AngularJS project, I am using owl-carousel and attempting to reinitialize the carousel after a change in data by using
$(element).data('owlCarousel').destroy();
while also removing this block:
<div class="owl-wrapper">
<div class="owl-item" ></div>
<div class="owl-item" ></div>
<div class="owl-item" ></div>
<div class="owl-item" ></div>
<div class="owl-item" ></div>
</div>
I have tried the following code:
if(typeof $(element).data('owlCarousel') != 'undefined'){
$(element).data('owlCarousel').destroy();
$(element).find(".owl-item").removeClass("owl-item");
}
While it works fine on page load, it does not function correctly when there is a change in the data. For example, if I have 5 items to display, I expect to see only 5 blocks like
<div class="owl-item" ></div>
, but I end up with more empty blocks.