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

Commit 0d4c2e2

Browse files
bekospkozlowski-opensource
authored andcommitted
refactor(carousel): use track by in template
Closes #1723
1 parent 3e938bd commit 0d4c2e2

File tree

3 files changed

+7
-15
lines changed

3 files changed

+7
-15
lines changed

src/carousel/carousel.js

+2-10
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@
99
angular.module('ui.bootstrap.carousel', ['ui.bootstrap.transition'])
1010
.controller('CarouselController', ['$scope', '$timeout', '$transition', function ($scope, $timeout, $transition) {
1111
var self = this,
12-
slides = self.slides = [],
12+
slides = self.slides = $scope.slides = [],
1313
currentIndex = -1,
1414
currentTimeout, isPlaying;
1515
self.currentSlide = null;
1616

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

99-
$scope.select = function(slide) {
100-
self.select(slide);
101-
};
102-
10399
$scope.isActive = function(slide) {
104100
return self.currentSlide === slide;
105101
};
106102

107-
$scope.slides = function() {
108-
return slides;
109-
};
110-
111103
$scope.$watch('interval', restartTimer);
112104
$scope.$on('$destroy', resetTimer);
113105

src/carousel/docs/demo.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ <h4>Slide {{$index}}</h4>
1212
</div>
1313
<div class="row">
1414
<div class="col-md-6">
15-
<a class="btn btn-info" ng-click="addSlide()">Add Slide</a>
15+
<button type="button" class="btn btn-info" ng-click="addSlide()">Add Slide</button>
1616
</div>
1717
<div class="col-md-6">
1818
Interval, in milliseconds: <input type="number" class="form-control" ng-model="myInterval">

template/carousel/carousel.html

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<div ng-mouseenter="pause()" ng-mouseleave="play()" class="carousel" ng-swipe-right="prev()" ng-swipe-left="next()">
2-
<ol class="carousel-indicators" ng-show="slides().length > 1">
3-
<li ng-repeat="slide in slides()" ng-class="{active: isActive(slide)}" ng-click="select(slide)"></li>
2+
<ol class="carousel-indicators" ng-show="slides.length > 1">
3+
<li ng-repeat="slide in slides track by $index" ng-class="{active: isActive(slide)}" ng-click="select(slide)"></li>
44
</ol>
55
<div class="carousel-inner" ng-transclude></div>
6-
<a class="left carousel-control" ng-click="prev()" ng-show="slides().length > 1"><span class="icon-prev"></span></a>
7-
<a class="right carousel-control" ng-click="next()" ng-show="slides().length > 1"><span class="icon-next"></span></a>
6+
<a class="left carousel-control" ng-click="prev()" ng-show="slides.length > 1"><span class="icon-prev"></span></a>
7+
<a class="right carousel-control" ng-click="next()" ng-show="slides.length > 1"><span class="icon-next"></span></a>
88
</div>

0 commit comments

Comments
 (0)