Troubleshooting problem with owl-carousel and ng-repeat in AngularJS

I have implemented an owl-carousel for my website's carousel functionality. The design of my carousel is similar to the one showcased here: . During my research, I found a solution on Stack Overflow which I integrated into my code with a directive in the controller provided below:

.directive('owlCarousel', function(){
    return {
        restrict: 'E',
        transclude: false,
        link: function (scope) {
            scope.initCarousel = function(element) {
                // provide any default options you want
                var defaultOptions = {
                    autoplay:true,
                    autoplayTimeout:2500,
                    loop:false,nav : true,
                    responsiveClass:true,
                    margin: 30,
                    responsive:{
                        0:{items:1},
                        767:{items:3},
                        992:{items:4}
                    }
                };
                var customOptions = scope.$eval($(element).attr('data-options'));
                // combine the two options objects
                for(var key in customOptions) {
                    defaultOptions[key] = customOptions[key];
                }
                // init carousel
                $(element).owlCarousel(defaultOptions);
            };
        }
    };
}).directive('owlCarouselItem', [function() {
    return {
        restrict: 'A',
        transclude: false,
        link: function(scope, element) {
            // wait for the last item in the ng-repeat then call init
            if(scope.$last) {
                scope.initCarousel(element.parent());
            }
        }
    };
}]);

Everything seems to be working fine, except for one issue. The height of the last item in the carousel extends beyond the other items below it.

If you take a look at the display above, you will notice the height discrepancy of the last item. Can someone please guide me on how to resolve this issue and identify the root cause? Any assistance would be greatly appreciated.

Answer №1

Give this a shot:

.directive('owlCarousel', function(){
    return {
        restrict: 'EA',
        transclude: false,
        link: function (scope, element, attrs) {
            scope.launchCarousel = function() {
                // set any default options you prefer
                var defaultOptions = {
                    autoplay:true,
                    autoplayTimeout:2500,
                    loop:false,nav : true,
                    responsiveClass:true,
                    margin: 30,
                    responsive:{
                        0:{items:1},
                        767:{items:3},
                        992:{items:4}
                    }
                };
                $(element).owlCarousel(defaultOptions);
            };
        }
    };
}).directive('owlCarouselItem',[function() {
     return function(scope) {
     if (scope.$last) {
        scope.launchCarousel();
     }
    };
  }]);

Take a look at the solution provided in this question to see what worked for me.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

How to update an object property in React using checkboxes

I am currently navigating the world of react and have encountered a challenging issue. I am in the process of developing an ordering application where users can customize their orders by selecting different ingredients. My approach involves using checkboxe ...

The process of retrieving a comprehensive list of all event listeners in JavaScript or jQuery

When clicking on a particular link, I have a list of links that use AJAX to retrieve the appropriate file. For example, let's say I have files a.php and b.php in the "pages" folder. Clicking on the first link retrieves all the data from a.php, while c ...

JavaScript - Capture the Values of Input Fields Upon Enter Key Press

Here's the input I have: <input class="form-control" id="unique-ar-array" type="text" name="unique-ar-array" value="" placeholder="Enter a keyword and press return to add items to the array"> And this is my JavaScript code: var uniqueRowsArr ...

I am looking for a way to extract all values from an HTML table using JavaScript and store them in an associative array or

I am in need of sending each ID book along with its quantity and cost using the post method through ajax. However, I am struggling to figure out how to create an array for this purpose. One option is to place all IDs and values within hidden inputs, but I ...

What is a sophisticated approach to overriding a jQuery method specifically within a plugin?

Today, my brain is in a bit of a fog where I can't seem to find an elegant solution to this issue. I've recently come into possession of a plugin that I need to tweak in order to pass an enabled or disabled state to it, allowing it to detach all ...

Using a text box in jQuery to perform basic calculations is a straightforward process

<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Creating a Lens Calculator Web App</title> <link href="http://code.jquery.com/mobile/1.0a3/jque ...

Measuring the height of a div element using Vuejs

Let me explain my current situation: I am trying to determine the height of a DIV component in order to dynamically inform its child component about its size. I have been working on implementing manual loading mode, but I have encountered an issue where t ...

What is the best way to test a component that does not properly handle a rejected promise using `wait` in the react-testing-library?

Looking to simulate a failed AJAX request scenario when placing an order on an online shopping store. Additionally, users can choose to subscribe only if the order placement is successful. Currently facing issues with handling Promise rejection in the tes ...

Using CSS on a randomly selected div that is chosen after dividing the main div each time it is clicked

Imagine a square box displayed as a "div" element. When you click on it, it splits into an n x n grid with each square having a random background color. However, the issue I am encountering is that I want to apply additional CSS to each of these randomly c ...

Unable to choose element within the interfaces of the DWR 921 Router's management page

When attempting to utilize Selenium in Python to send SMS using my DLink DWR-921 router, I am encountering an issue where I cannot select any element on the document. I have tried using td, table, and body, but none of them seem to work. Additionally, I at ...

Customize your payment with a PayPal button tailored to your desired price

I've been tasked with creating a dynamic PayPal button that can receive different values based on user choices. The website has so many options that creating separate buttons for each choice doesn't seem feasible. I've tried researching solu ...

Is there a way to adjust the height relative to the viewport in Bootstrap 5 for values other than 100?

Attempting to create a new type of div using a custom stylesheet with minimal non-bootstrap css. I am trying to convert each style rule from my django static files CSS into a bootstrap class, but I am stuck on viewport-based sizing. Prior to discovering t ...

It appears that the home page of next.js is not appearing properly in the Storybook

Currently, I am in the process of setting up my next home page in storybooks for the first time. Following a tutorial, I successfully created my next-app and initialized storybooks. Now, I am stuck at importing my homepage into storybooks. To achieve this, ...

What is the best way to reload sections of a webpage using Django and jQuery?

In a demonstration project I've created, there are two links labeled '1' and '2'. When either link is clicked, the number displayed will change to 1 or 2 accordingly. models.py class Count(models.Model): num = models.IntegerF ...

Utilize LESS Bootstrap as a guide for incorporating content

I have been struggling to properly integrate Bootstrap into my LESS file. Currently, I am adding Bootstrap to my project using NPM. If I simply use the following import statement in my LESS file: @import (reference) 'node_modules/bootstrap/less/boot ...

Is it possible to amalgamate CSS declarations together?

You have the ability to combine CSS selectors by using a comma, like in this example: .one, .two { color: #F00; } <div class="one">One</div> <div class="two">Two</div> Using this method produces the same outcome as specifying ...

Dealing with 404 Errors in AngularJS using ui-router's resolve feature

As a newcomer to AngularJS and ui-router, I am currently facing the challenge of handling 404 errors for resources not found. My goal is to display an error message without changing the URL in the address bar. Here is how I have configured my states: app ...

Creating a transitioning effect using CSS for fading in and out

My challenge lies in implementing a smooth transition effect for my drop-down menu using CSS. I want the menu to fade-in slowly and fade-out slowly when the user clicks on it. The menu is built with ul elements and starts off hidden. The visibility states ...

The button is malfunctioning and adjust the border hue

I've been experimenting with creating a Firefox Extension, but I'm struggling to get the button in the popup to work as intended. The desired functionality is for the red border to change to green when the button is clicked, but I can't ...

Tips for executing shallow array duplication in mobx

In my code, I have been utilizing the lodash function _.CloneDeep to copy an object array. However, I actually need a shallow copy of this array. Here's the relevant code snippet: @observable.ref trades: Array<TradeType> = []; @action attachN ...