最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

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

matteradmin7PV0评论

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>
Post a comment

comment list (0)

  1. No comments so far