Skip to content

Instantly share code, notes, and snippets.

@codeaholicguy
Created January 19, 2016 06:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codeaholicguy/56f349d2d350640d9148 to your computer and use it in GitHub Desktop.
Save codeaholicguy/56f349d2d350640d9148 to your computer and use it in GitHub Desktop.
// index.html
<div ng-controller="SlideShowController">
<slide-show slides="slides"></slide-show>
</div>
// slide-show.html
<div class="slideshow">
<ul class="slideshow-slides">
<li ng-repeat="slide in slides" ng-class="{ active: $index == activeIndex }">
<figure>
<img ng-src="{{ slide.imageUrl }}" />
<figcaption ng-show="slide.caption">{{ slide.caption }}</figcaption>
</figure>
</li>
</ul>
<ul class="slideshow-dots">
<li ng-repeat="slide in slides" ng-class="{ active: $index == activeIndex }">
<a ng-click="jumpToSlide($index)">{{ $index + 1 }}</a>
</li>
</ul>
</div>
// js
app.controller("SlideShowController", function($scope) {
$scope.slides = [{
imageUrl: "image.jpg",
caption: "This is image"
}, {
imageUrl: "image.jpg",
caption: "This is image"
}];
});
app.directive("slideShow", function() {
return {
restrict: 'E',
scope: {
slides: '='
},
template: 'slide-show.html',
link: function($scope, element, attrs) {
$scope.activeIndex = 0;
$scope.jumpToSlide = function(index) {
$scope.activeIndex = index;
};
}
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment