cachaito
11/1/2013 - 6:26 PM

Prosty slider obrazków w Angularze

//w kontrolerze
$scope.photos = [
  {
    id : 1,
    src : 'http://lorempixel.com/460/460/technics/6',
    desc : 'aaa'
  },
  {
    id : 2,
    src : 'http://lorempixel.com/460/460/technics/5',
    desc : 'bbb'
  },
  {
    id : 3,
    src : 'http://lorempixel.com/460/460/technics/4',
    desc: 'ccc'
  },
  {
    id : 4,
    src : 'http://lorempixel.com/460/460/technics/3',
    desc: 'ddd'
  }
]

$scope.step = 0;

$scope.nextImage = function() {
  $scope.animation = 'animate';
  if ($scope.step >= $scope.photos.length -1) {
    $scope.step = 0;
  } else {
    $scope.step += 1;
  }
}

$scope.prevImage = function() {
  if ($scope.step <= 0) {
    $scope.step = $scope.photos.length -1;
  } else {
    $scope.step -= 1;
  }
}