Skip to content

Commit

Permalink
Added a dynamic ngx-bootsrtrap carousel
Browse files Browse the repository at this point in the history
  • Loading branch information
ImsirovicAjdin committed Aug 29, 2019
1 parent 8066cd1 commit ecc7dab
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 1 deletion.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 23 additions & 0 deletions src/app/carousels/carousels.component.html
Expand Up @@ -27,3 +27,26 @@ <h3>Third slide label</h3>
</div>
</slide>
</carousel>

<carousel [(activeSlide)]="activeSlideIndex" >
<slide *ngFor="let slide of slides; let index=index">
<img [src]="slide.image" alt="image slide" style="display: block; width: 100%; height: 100px; background: orange;">

<div class="carousel-caption">
<h4>Slide {{index}}</h4>
<p>{{slide.text}}</p>
</div>
</slide>
</carousel>
<br/>
<div>
<button type="button" class="btn btn-info"
(click)="addSlide()">Add Slide
</button>
<button type="button" class="btn btn-info"
(click)="removeSlide()">Remove Current
</button>
<button type="button" class="btn btn-info"
(click)="removeSlide(2)">Remove #3
</button>
</div>
22 changes: 21 additions & 1 deletion src/app/carousels/carousels.component.ts
Expand Up @@ -4,4 +4,24 @@ import { Component } from '@angular/core';
selector: 'my-carousels',
templateUrl: './carousels.component.html'
})
export class CarouselsComponent { }
export class CarouselsComponent {
slides: { image: string }[] = [];
activeSlideIndex = 0;

constructor() {
for (let i = 0; i < 4; i++) {
this.addSlide();
}
}

addSlide(): void {
this.slides.push({
image: `assets/images/nature/${this.slides.length % 8 + 1}.jpg`
});
}

removeSlide(index?: number): void {
const toRemove = index ? index : this.activeSlideIndex;
this.slides.splice(toRemove, 1);
}
}

0 comments on commit ecc7dab

Please sign in to comment.