Skip to content
This repository has been archived by the owner on May 29, 2019. It is now read-only.

Commit

Permalink
refactor(carousel): use track by in template
Browse files Browse the repository at this point in the history
Closes #1723
  • Loading branch information
bekos authored and pkozlowski-opensource committed Feb 22, 2014
1 parent 3e938bd commit 0d4c2e2
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 15 deletions.
12 changes: 2 additions & 10 deletions src/carousel/carousel.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
angular.module('ui.bootstrap.carousel', ['ui.bootstrap.transition'])
.controller('CarouselController', ['$scope', '$timeout', '$transition', function ($scope, $timeout, $transition) {
var self = this,
slides = self.slides = [],
slides = self.slides = $scope.slides = [],
currentIndex = -1,
currentTimeout, isPlaying;
self.currentSlide = null;

var destroyed = false;
/* direction: "prev" or "next" */
self.select = function(nextSlide, direction) {
self.select = $scope.select = function(nextSlide, direction) {
var nextIndex = slides.indexOf(nextSlide);
//Decide direction if it's not given
if (direction === undefined) {
Expand Down Expand Up @@ -96,18 +96,10 @@ angular.module('ui.bootstrap.carousel', ['ui.bootstrap.transition'])
}
};

$scope.select = function(slide) {
self.select(slide);
};

$scope.isActive = function(slide) {
return self.currentSlide === slide;
};

$scope.slides = function() {
return slides;
};

$scope.$watch('interval', restartTimer);
$scope.$on('$destroy', resetTimer);

Expand Down
2 changes: 1 addition & 1 deletion src/carousel/docs/demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ <h4>Slide {{$index}}</h4>
</div>
<div class="row">
<div class="col-md-6">
<a class="btn btn-info" ng-click="addSlide()">Add Slide</a>
<button type="button" class="btn btn-info" ng-click="addSlide()">Add Slide</button>
</div>
<div class="col-md-6">
Interval, in milliseconds: <input type="number" class="form-control" ng-model="myInterval">
Expand Down
8 changes: 4 additions & 4 deletions template/carousel/carousel.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<div ng-mouseenter="pause()" ng-mouseleave="play()" class="carousel" ng-swipe-right="prev()" ng-swipe-left="next()">
<ol class="carousel-indicators" ng-show="slides().length > 1">
<li ng-repeat="slide in slides()" ng-class="{active: isActive(slide)}" ng-click="select(slide)"></li>
<ol class="carousel-indicators" ng-show="slides.length > 1">
<li ng-repeat="slide in slides track by $index" ng-class="{active: isActive(slide)}" ng-click="select(slide)"></li>
</ol>
<div class="carousel-inner" ng-transclude></div>
<a class="left carousel-control" ng-click="prev()" ng-show="slides().length > 1"><span class="icon-prev"></span></a>
<a class="right carousel-control" ng-click="next()" ng-show="slides().length > 1"><span class="icon-next"></span></a>
<a class="left carousel-control" ng-click="prev()" ng-show="slides.length > 1"><span class="icon-prev"></span></a>
<a class="right carousel-control" ng-click="next()" ng-show="slides.length > 1"><span class="icon-next"></span></a>
</div>

0 comments on commit 0d4c2e2

Please sign in to comment.