Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

133
Views
Bootstrap Carousel dissapears after removing element

I have a weird issue, for which I've been unable to identify the root cause. I have an angular app and it has a carousel that displays text instead of images, every slide has a remove button, it calls a method that receives the index and then removes the element from the carousel. If I remove any item but the first one the carousel then disappears.

Here is my example code, it's fully reproducible on stackblitz:

import { ChangeDetectorRef, Component } from '@angular/core';

@Component({
  selector: 'my-app',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css'],
})
export class AppComponent {
  name = 'Angular';

  myCarouselItems = ['slide 1', 'slide 2', 'slide 3'];

  constructor(private cdref: ChangeDetectorRef) {}

  deleteItem(index): void {
    this.myCarouselItems.splice(index, 1);
    this.cdref.detectChanges();
  }
}

HTML

<div id="carouselExampleControls" class="carousel slide" data-ride="carousel">
  <div class="carousel-inner">
    <div
      class="carousel-item"
      *ngFor="let item of myCarouselItems; index as i; let isFirst = first"
      [ngClass]="{ active: i === 0 }"
      style="text-align: center;"
    >
      <p>{{ item }}</p>
      <a style="cursor: pointer" (click)="deleteItem(i)">Delete this element</a>
    </div>
  </div>
  <a
    class="carousel-control-prev"
    href="#carouselExampleControls"
    role="button"
    data-slide="prev"
    style="background-color: red;"
  >
    <span class="carousel-control-prev-icon" aria-hidden="true"></span>
    <span class="sr-only">Previous</span>
  </a>
  <a
    class="carousel-control-next"
    href="#carouselExampleControls"
    role="button"
    data-slide="next"
    style="background-color: red;"
  >
    <span class="carousel-control-next-icon" aria-hidden="true"></span>
    <span class="sr-only">Next</span>
  </a>
</div>

Link to the stackblitz https://stackblitz.com/edit/angular-simple-bootstrap-navbar-sdzr55?file=src/app/app.component.html

Anybody knows how can I fix this?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!