Troubleshooting: Why are my Angular 8 Carousel Slide Animations not functioning

Looking to create a carousel slideshow with images sliding from right to left and smoothly transition to the next image.

All the necessary code can be found in this STACKBLITZ

Here is the HTML snippet:

<ngb-carousel *ngIf="images" [showNavigationArrows]="showNavigationArrows" [showNavigationIndicators]="showNavigationIndicators">
    <ng-template ngbSlide *ngFor="let image of images">
      <div class="picsum-img-wrapper">
        <img [src]="image" alt="Random slide">
      </div>
      <div class="carousel-caption">
        <button>Touch to start</button>
      </div>
    </ng-template>
  </ngb-carousel>

The carousel animations for the smooth transitions:

animations: [
    trigger('slide', [
      state('previousLeft', style({
        display: 'none',
        transform: 'translateX(-100%)'
      })),
      state('previousRight', style({
        display: 'none',
        transform: 'translateX(100%)'
      })),
      transition('hidden => activeLeft, previousRight => activeLeft', [
        style({
          display: 'block',
          transform: 'translateX(100%)'
        }),
        animate('0.6s')
      ]),
      transition('hidden => activeRight, previousLeft => activeRight', [
        style({
          display: 'block',
          transform: 'translateX(-100%)'
        }),
        animate('0.6s')
      ]),
      transition('activeLeft => previousLeft, activeRight => previousRight,' +
                 'activeRight => previousLeft, activeLeft => previousRight,' +
                 'active => previousLeft, active => previousRight', [
        style({
          display: 'block'
        }),
        animate('0.6s')
      ])
    ])
  ],

Desired functionality similar to this example: Another Stackblitz

Any assistance would be greatly appreciated to achieve this feature.

Answer №1

Implement the following code snippet using setTimeout();

ngOnInit() {
  this.getData();
} 

private getData() : void {
  
  /*Fetch Image*/
  let subscribe = this.imageService.getImage().subscribe(res => {
      
      this.imageList = res;
       
      setTimeout(() => {
        
        this.setEvent();
      }, 300)
        
    }, error => {
    
    console.log('error', error);

  }) 
  

}


private setEvent() : void {

  /*Create slide event e.g. swiper event...*/


}

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

Make individual term span the entire width of 100%

Is it feasible to expand a single word like "News" to occupy 100% width of the div element? My goal is to automatically adjust letter spacing and justify individual words. Currently, I have a menu with items such as: Home About News Etc It would be idea ...

Toggle visibility of div content when hovering over a link by leveraging the data attribute, with the div initially visible

I have a collection of links: <p><a href="#" class="floorplan initial" data-id="king"><strong>King</strong></a><br> 4 Bedrooms x 2.5 Bathrooms</p> <p><a href="#" class="floorplan" data-id="wood">< ...

Ensure that only the admin is able to make something vanish for everyone else

Is there a way to hide content for everyone except the admin? Currently, I have this code implemented but it only works when a user is not logged in. When another user logs in, the content is still visible. <?php if( isset($_SESSION['username&a ...

Passing a class as a parameter in Typescript functions

When working with Angular 2 testing utilities, I usually follow this process: fixture = TestBed.createComponent(EditableValueComponent); The EditableValueComponent is just a standard component class that I use. I am curious about the inner workings: st ...

Generating automatic slugs in Django is a useful feature to simplify URL generation

I'm in the process of creating a blog and I am looking for a way to automatically generate the slug so that the URL can be based on the article title. Thank you very much ...

What is the best way to update or change a value in a JSON file?

This specific file is structured in JSON format shown below: { "ClusterName": { "Description": "Name of the dbX Cluster", "Type": "String", "MinLength": "1", "MaxLength": "64", "AllowedPattern": "[-_ a-zA-Z0-9]* ...

steps to determine if a page is being refreshed

Is there a way to prevent the page from reloading when the user clicks the reload button in the browser? I attempted to use this code, but my break point is not triggering. ngOnInit() { this.router .events .subscribe((e: RouterEvent) = ...

Adjust the DIV dimensions to fit the background image perfectly

My question involves a DIV element with a specific style applied to it. .vplayer-container .logo { position: absolute; bottom: 50px; right: 10px; background: url(../img/logo.png) no-repeat; border: 1px solid #000000; max-width: 50px; max-height: 50 ...

Interactive Image Effects with Hover using HTML and JavaScript

I have observed that the transform works fine, but there is a slight issue when initially hovering or touching the image. After the first touch or hover, everything works great. Any assistance on fixing this minor issue would be greatly appreciated. Thank ...

The configuration object is invalid. Webpack has been initialized with a configuration object that does not conform to the API schema

I recently created a basic helloworld react app through an online course, but I encountered the following error: Invalid configuration object. Webpack has been initialized with a configuration object that does not adhere to the API schema. - configur ...

Place two anchors side by side using inline-blocks without using the float property

Is there a way to align two buttons next to each other without using floating? I have encountered an issue where adding a width to one of the buttons causes it to jump down and be on a different line than the other button. The buttons are centered, so th ...

I am having trouble inserting a table from a JSON object into an HTML file

getJSON('http://localhost:63322/logs', function(err, data) { if (err !== null) { alert('Something went wrong: ' + err); } else { //var myObj = JSON.parse(data); // document.getElementById("demo").innerHTML = myObj.ad_soy ...

Challenges encountered when implementing a personal library in a separate project

After updating a library I own, I seem to have encountered an issue when trying to use it in another project. However, the reason for this problem eludes me. A multitude of error logs with a similar theme are appearing: ERROR in ./node_modules/@company-na ...

I am attempting to gather user input for an array while also ensuring that duplicate values are being checked

Can someone assist me with the following issue: https://stackblitz.com/edit/duplicates-aas5zs?file=app%2Fapp.component.ts,app%2Fapp.component.html I am having trouble finding duplicate values and displaying them below. Any guidance would be appreciated. I ...

Styling targeted to a particular div

Currently, I am attempting to showcase a docx file on my webpage by converting it to HTML and then displaying it. However, this method generates CSS with rules that end up impacting the entire document. For instance, it changes all links to blue which co ...

Is it possible to configure a unique Bearer Access Token in the "angular-oauth2-oidc" library?

For my Facebook login, I have set up a custom endpoint where the client sends the Facebook access token. In my Ionic App, I use the '@ionic-native/facebook/ngx' package to retrieve this token. Within a Laravel Json API controller, I utilize Soci ...

Using jQuery to update a specific item in a list

My current project involves developing an Image Gallery app. It uses <img> tags within li elements. The code snippet is as follows: var $slideR_wrap = $(".slideRoller_wrapper"); var $slidesRoller = $slideR_wrap.find(".slidesRoller"); var $slideR ...

ASP: The submenu items remain visible

I must express my gratitude for the wealth of knowledge this site has provided me with. It has been an invaluable resource for me this year, even though I have scoured every corner and still come up empty-handed. Allow me to simplify the situation at hand ...

Angular: How can I apply animation to rotate an image within a component?

Within my map application, I have implemented a component called compass component. I am seeking a way to programmatically rotate this compass with animation as the map is rotated. The solution involves utilizing angular animation. To achieve this functio ...

Exploring the capabilities of ExcelJS for reading xlsx files within an Angular environment

I'm trying to access a source file, make some changes to it, and then provide it for the user to download. However, I am facing an issue with reading the source file from my project directory. Below is my implementation using excelJS for file reading: ...