The click event on a card is not triggering on a cloned item in the Owl Carousel 2

I have implemented owl carousel to showcase products, where each product is displayed on a card with an 'add to cart' button. However, I am facing an issue where the 'add to cart' button on a cloned item does not trigger the click event.

I understand that there are numerous questions regarding this problem, and the common solution is to set the loop option to false. Nonetheless, I require the loop option to be enabled in my scenario.
loop: false

Moreover, the carousel click functionality is not working for me either,

$('.bstsrv-carousel').on('click', '.item', function () {
      alert("click");
  });

Below is the code snippet for my carousel setup:

<div class="carousel-wrap">
    <div class="owl-carousel owl-theme bstsrv-carousel">
        <div class="product card" product-id="i" product-color="#D18B49" *ngFor="let item of packages; let i = index">
            <div class="thumbnail">
                <img src="../../assets/img/carousel/main/carousel1.jpg" />
            </div>
            <h1 class="title">{{ item.name }}</h1>
            <div class="product-description stack-card-desc">
                <ul>
                    <li *ngFor="let desc of item.desc">
                        {{ desc }}
                    </li>
                </ul>
            </div>
            <div class="product-checkout-actions daily-offer-cart">
                <button class="add-to-cart dailyoffer-add" *ngIf="!item.isInCart" name="'addtocart' + i"
                    (click)="AddToCart(item)">
                    Add to Cart
                </button>
                <button class="add-to-cart dailyoffer-add" *ngIf="item.isInCart" name="'removecart' + i"
                    (click)="removeCart(item)">
                    Remove
                </button>
            </div>
        </div>
    </div>
</div>

Here are the carousel options I have set:

  $(".bstsrv-carousel").owlCarousel({
    items: 3,
    loop:  true,
    stagePadding: 0,
    margin: 0,
    autoplay: true,
    autoplayTimeout: 4000,
    autoplayHoverPause: true,
    nav: true,
    dots: false,
    responsiveClass: true,
    responsive: {
      0: {
        items: 3,
        nav: true
      }
    }
  });

Answer №1

It appears that you are utilizing jQuery to configure the owl-carousel. It is recommended to use a library designed specifically for Angular: https://github.com/vitalii-andriiovskyi/ngx-owl-carousel-o

Angular follows a distinct approach for initializing its template code, which may not be activated when using the jQuery component. Therefore, when the jQuery component duplicates one of its carousel items, the Angular code may not operate as expected. Transitioning to the Angular jQuery carousel library is advisable.

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

D3 Chart: What is the best way to insert images into a node?

Within the jsFiddle demo provided in this query, there is code displayed. I am curious about how I can assign images to each node. var graph = { "nodes":[ {"name":"1","rating":90,"id":2951}, ] } You can access my jsFiddle Demo through this ...

What is the best way to adjust the size of carousel images within a box element?

How can I ensure that carousel pictures are displayed clearly within the box without overflowing? The code I tried resulted in the pictures overflowing from the box and not being visible clearly. How can I resolve this issue? .container { width: 1490px; ...

Ensuring website responsiveness beyond just the carousel

I found a carousel (inspired by: https://codepen.io/dobladov/pen/kXAXJx) that fetches images from an API. The carousel will switch images as you click on a different image or use the "previous" or "next" buttons. While there are many examples of putting te ...

Restricting thumbnail scrolling within the visible area in a jQuery/CSS Gallery/Slideshow

Is it possible to create a gallery slideshow feature where the selected thumbnail's image source will be displayed in the main image container? I believe I can implement that part successfully. Currently, my challenge is defining the thumbnail scroll ...

No matter what I try, the design of my dialog box remains stubbornly unchanged

I am attempting to increase the width of my dialog box while also adding horizontal middle borders. It seems that my bootstrap for the site does not include these elements. How can I rectify this issue? Here is my code: $(document).ready(function() { ...

Stop unwanted clicking on inactive buttons in Angular

I want to make sure that disabled buttons cannot be clicked by users who might try to remove the disabled attribute and trigger an action. Currently, I have this code to handle the situation: <button [disabled]="someCondition" (click)="executeAction()" ...

What is the best way to crop an image to focus solely on the center portion?

Using Bootstrap 3, how can I display an image cropped in a .col-sm-6 grid column? The image is 720px wide. Typically, with the .img-responsive class, the image will resize proportionally when the display size changes. However, I want to crop the left and ...

Encountering a problem while verifying pattern using regular expressions

I'm facing an issue when manually checking if my inputs match the specified patterns. Below is the function I am using for this check: if (!$element.attr("pattern")) return true; let pattern = $element.attr("pattern"); le ...

Gatsby: A guide on inserting unadulterated HTML within the head section

Is it possible to insert raw HTML into the <head></head> section of every page in a Gatsby.js project? I need to add a string of HTML for tracking purposes, including inline and external script tags, link tags, and meta tags. For example, here ...

JQuery not updating the visibility of elements with the "d-none" class when switching to another tab

Currently, I am attempting to conceal a specific section of my webpage in order to display a "loading" spinner. I achieve this by employing jQuery to add the class "d-none" and remove the class "d-none" from the desired element that needs to be hidden or s ...

Reveal Content once you give us a thumbs up on Facebook

Is there HTML/PHP code that can display specific content only after a user clicks the "Like" button on an external website, not an app? ...

Locate every div element that contains a span id matching any word in a specified list

I'm attempting to create a script that will add a class based on whether or not a list item's span id contains certain words from a list. The list follows this structure: <div id="main_list"> <li class> <a data-item_ ...

Navigational assistance on the keyboard - Improving Accessibility

My situation involves selecting an option from a dropdown menu on X-page, which triggers the opening of Modal-1 while disabling the background. If a selection is made within Modal-1, it leads to Modal-2. I am facing two issues/questions: Upon opening Moda ...

Having Trouble Styling Radio Buttons with CSS

Hello, I'm facing an issue with hiding the radio button and replacing it with an image. I was successful in doing this for one set of radio buttons, but the second set in another row is not working properly. Additionally, when a radio button from the ...

The HTML5 ondrop event finishes executing before zip.js completes its operations

I'm facing a problem where I need to use a datatransferitemlist asynchronously, which contradicts the functionality outlined in the specifications. According to the specs, access to the dataTransfer.items collection is restricted once the event ends. ...

Center the Search Form for improved visibility

As a novice web developer, I am in the process of building a website similar to LinkedIn using Bootstrap-4. My current challenge is how to center my form within the navbar. Below is a snippet of the code from my webpage: <body> < ...

Trouble Arising from the Lack of Coordination Between CSS Transition and JavaScript Update Triggered by Element

I'm currently working on a web development project that involves a list of clickable elements. When one of these elements is clicked, it should become active and trigger a CSS transition (such as a transform) with a duration of 200ms. Additionally, I ...

Embed video with a custom thumbnail in an iframe

Hello everyone! I'm a first-time user on stackoverflow seeking some help. Currently, I am using Dreamweaver to work with HTML and CSS in order to build a website. My task involves sourcing a video from a television archive and embedding it onto my si ...

Unlocking the Interactive Potential of CSS Across All Screen Formats

I am currently working on transforming my website into an engaging and interactive platform. My first challenge: The alignment of the logo image does not meet my desired specifications. Whenever the screen width exceeds 1200 pixels, there seems to be exc ...

What is the best way to use a CSS class in my script specifically for specific screen sizes?

Utilizing bootstrap 4, my code is executing a for loop to generate eight divs with the class "item". To display five items per row, I am using the class "col-2". However, this results in six items being shown in a single row. Since I cannot include the o ...