首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ngx-owl-carousle-o分页在Angular 10中不起作用

ngx-owl-carousle-o分页在Angular 10中不起作用
EN

Stack Overflow用户
提问于 2020-10-20 21:36:45
回答 1查看 584关注 0票数 0

我有一个使用Angular 10的简单应用程序,我在其中使用了ngx-owl-carousel。我对分页有问题。当我尝试单击“下一页”时,它不能按预期工作,并出现此错误。

代码语言:javascript
复制
ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked. Previous value: 'translate3d(-297px,0px,0px)'. Current value: 'translate3d(-1488px,0px,0px)'.
    at throwErrorIfNoChangesMode (core.js:5625)
    at bindingUpdated (core.js:13962)
    at bindingUpdated2 (core.js:13977)
    at bindingUpdated4 (core.js:13986)
    at Module.ɵɵpureFunction5 (core.js:24421)
    at StageComponent_Template (ngx-owl-carousel-o.js:3393)
    at executeTemplate (core.js:7449)
    at refreshView (core.js:7318)
    at refreshComponent (core.js:8465)
    at refreshChildComponents (core.js:7126)

carousel.component.html

代码语言:javascript
复制
    <div class="wrapper">
    <h3 *ngIf="data.products.length !== 0" class="category-title">{{data.title}}</h3>

    <owl-carousel-o (dragging)="isDragging = $event.dragging" [options]="customOptions">

        <ng-container *ngFor="let slide of data.products">
            <ng-template carouselSlide>
                <a *ngIf="slide.product_type == 1 || slide.product_type == 4" [owlRouterLink]="['/animations', slide.id]" [stopLink]="isDragging"  class="image">
                    <img [src]="slide.feature_avatar.xxxdpi" [alt]="" [title]="slide.name">
                    <div class="title">
                        <h4>{{slide.name}}</h4>
                    </div>
                </a>
                <a *ngIf="slide.product_type == 3" [owlRouterLink]="['/animations/collection', slide.id]" [stopLink]="isDragging"  class="image">
                    <img [src]="slide.feature_avatar.xxxdpi" [alt]="" [title]="slide.name">
                    <div class="title">
                        <h4>{{slide.name}}</h4>
                    </div>
                </a>
            </ng-template>
        </ng-container>

    </owl-carousel-o>

</div>

carousel.componen.ts

代码语言:javascript
复制
import { Component, OnInit, Input } from '@angular/core';
import { HomeItem, Result } from 'src/app/shared/models/homeMain.model';
import { OwlOptions } from 'ngx-owl-carousel-o';

@Component({
  selector: 'carousel',
  templateUrl: './carousel.component.html',
  styleUrls: ['./carousel.component.scss']
})
export class CarouselComponent implements OnInit {
  customOptions: OwlOptions;
  isDragging: boolean;
  constructor() { }

  @Input() data: Result

  ngOnInit() {
    this.customOptions = {
      rtl: false,
      loop: true,
      lazyLoad: true,
      mouseDrag: true,
      touchDrag: true,
      pullDrag: false,
      dots: true,
      navSpeed: 700,
      navText: ['', ''],
      margin: 10,
      stagePadding: 10,
      responsive: {
        0: {
          items: 2
        },
        400: {
          items: 3
        },
        740: {
          items: 3
        },
        940: {
          items: 5
        },
        1024: {
          items: 5
        }
      },
      nav: false
    }
  }
}

它在angular 8中工作,但在angular 10中不工作,我还有另一个问题,这个路由不能工作,甚至不能点击。

EN

回答 1

Stack Overflow用户

发布于 2021-01-21 16:08:50

问题是*ngIf指令是滑块中的一个标记。将这样的*ngIf指令放入<ng-template carouselSlide>

代码语言:javascript
复制
<owl-carousel-o (dragging)="isDragging = $event.dragging" [options]="customOptions">
    <ng-template carouselSlide *ngIf="slide.product_type == 1 || slide.product_type == 4">
        <a [owlRouterLink]="['/animations', slide.id]" [stopLink]="isDragging" class="image">
            <img [src]="slide.feature_avatar.xxxdpi" [alt]="" [title]="slide.name">
            <div class="title">
                <h4>{{slide.name}}</h4>
            </div>
        </a>
    </ng-template>

    <ng-template carouselSlide *ngIf="slide.product_type == 3">
        <a [owlRouterLink]="['/animations/collection', slide.id]" [stopLink]="isDragging" class="image">
            <img [src]="slide.feature_avatar.xxxdpi" [alt]="" [title]="slide.name">
            <div class="title">
                <h4>{{slide.name}}</h4>
            </div>
        </a>
    </ng-template>
</owl-carousel-o>
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64446337

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档