NetanelBasal
9/11/2017 - 7:52 PM

ngcarousel7.ts

export class CarouselComponent implements AfterViewInit {
  ...
  @ViewChild('carousel') private carousel : ElementRef;
  
  constructor( private builder : AnimationBuilder ) {
  }
  
  next() {
    if( this.currentSlide + 1 === this.items.length ) return;

    this.currentSlide = (this.currentSlide + 1) % this.items.length;

    const offset = this.currentSlide * this.itemWidth;

    const myAnimation : AnimationFactory = this.builder.build([
       animate(this.timing, style({ transform: `translateX(-${offset}px)` }))
    ]);

    this.player = myAnimation.create(this.carousel.nativeElement);
    this.player.play();
  }
}