Html 在克隆项目owl转盘2上未触发卡上的单击事件

Html 在克隆项目owl转盘2上未触发卡上的单击事件,html,css,owl-carousel,Html,Css,Owl Carousel,我使用owl carousel来显示产品,因为我在卡片上列出了带有“添加到购物车”按钮的产品,但克隆项目上的“添加到购物车”按钮不会触发单击事件 我知道这方面有很多问题,但在所有情况下,答案都是使循环选项为false,但我希望在我的情况下使用循环选项。 循环:false 此外,旋转木马单击对我也不起作用, $('.bstsrv carousel')。在('click','.item',函数(){ 警报(“点击”); }); 这是我的旋转木马: <div class="carousel-wr

我使用owl carousel来显示产品,因为我在卡片上列出了带有“添加到购物车”按钮的产品,但克隆项目上的“添加到购物车”按钮不会触发单击事件

我知道这方面有很多问题,但在所有情况下,答案都是使循环选项为false,但我希望在我的情况下使用循环选项。
循环:false

此外,旋转木马单击对我也不起作用,
$('.bstsrv carousel')。在('click','.item',函数(){
警报(“点击”);
});

这是我的旋转木马:

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

看起来您正在使用jQuery设置owl转盘。您应该使用专门为角度设置的库:


Angular有一种非常特殊的初始化模板代码的方法,如果使用jQuery组件,则不会触发该方法。因此,基本上,当jQuery组件克隆它的一个转盘项目时,角度代码将不起作用。迁移到angular jQuery carousel库应该是一个不错的选择。

我刚才复制了我的错误,但我在使用时更改了代码,但不起作用angular有一个原因,我选择了jQuery,这只是我代码的一半,我正在处理的carousel中有很多东西,angular way无法做到。angular有一种非常具体的初始化它的方法模板代码,如果使用jQuery组件,则不会触发该代码。因此,基本上,当jQuery组件克隆它的一个转盘项目时,角度代码将不起作用。迁移到angular jQuery carousel库应该是一个不错的选择。使用此用法更新答案
https://ng-bootstrap.github.io/#/components/carousel/examples
angular library用于此。
  $(".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
      }
    }
  });