ThierryDD
4/16/2018 - 4:51 PM

Photos Swiping Animations - Direction

import { 
  // ...
  ChangeDetectorRef
} from '@angular/core';

// ...

@Component({
  // ...
})
export class AlbumComponent {

  // ...
  
  direction: string = null; // 🅰

  // ...

  constructor(private changeDetectorRef: ChangeDetectorRef) { } // 🅱

  slide(offset) {
    const nbPhotos = this.album.photos.length;
    this.direction = (offset < 0) ? "right" : "left"; // 🅲
    this.changeDetectorRef.detectChanges(); // 🅳
    this.current = (((this.current + offset) % nbPhotos) + nbPhotos) % nbPhotos;
  }

}