最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

html - Carousel with timer loads infinitely in Angular 18 - Stack Overflow

programmeradmin1浏览0评论

I have an issue: I am developing a web app in angular V18 my problem is when I implement a carousel this just have text and it must change every 3 seconds, but in the code when I want to see the page, it loads infinitely and doesn't show any text, image or anything... why? I would appreciate the suggest, I show the code below of the component carousel thank you.

carouselponent.ts

export class PievistaprincipalComponent {
   items = ['CONOCE COMO DARLE COMPETITIVIDAD A TU NEGOCIO.','ORGANIZA TUS IDEAS.','AUTOMATIZA TUS PROCESOS.','GENERA Y GESTIONA TU CADENA DE VALOR.'];
   private intervaloContador: any;

   animate = false;
   itemSeleccionado = "";
   public contador: number = 4; // Inicializamos el contador en 4 segundos
   constructor(){
     
   }
   ngOnInit() {
     this.itemSeleccionado = this.items[0];
     this.change(); //invoke from start web app here loads infintely and dont show nothing 
                    // more 
   }
   ngAfterViewOnInit(){

   }

   ngOnDestroy() {

   }



   change(){
     this.intervaloContador = setInterval(() => {
       this.contador--; // reduce the count by 1
       if (this.contador === 0) {
          this.contador = 4; // reloads count of slides 0
       }
       this.currentSlide(this.contador) //put a slide
     }, 3000); // every 3 seconds refresh
   }

   currentSlide(indice: any) {
     // console.log(indice);
     this.itemSeleccionado = this.items[indice];
     this.triggerAnimation();
   }

   triggerAnimation() {
     this.animate = false; // reloads state
     setTimeout(() => {
       this.animate = true; // activate the animation, this tipe of timer runs ok
     }, 10); // wait a bit to reload the class of element
   }

   resetAnimation() {
     this.animate = false; // clean the class after the animation
   }

}

carouselponent.html

<div class="carousel-container">
    <link
      rel="stylesheet"
      href=".css/4.1.1/animate.min.css"
    />    
    <div class="slider-container">
        <div class="slider">
            <h1 
                [ngClass]="{'animate__animated animate__backInRight': animate}" 
                (animationend)="resetAnimation()">
                {{itemSeleccionado}}
            </h1>
        </div>
        <div class="dot-container">
            <button class="btn" 
              *ngFor="let item of items; let ind=index" 
              (click)="currentSlide(ind)">
                <span class="dot"></span>
            </button>
        </div>
    </div>
</div>
发布评论

评论列表(0)

  1. 暂无评论