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

Commit 9b80ee1

Browse files
jsdevelwesleycho
authored andcommitted
feat(carousel): expose next and prev on controller
- Expose `prev` and `next` functions on the carousel controller Closes #4851 Closes #4853
1 parent 26d3103 commit 9b80ee1

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/carousel/carousel.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ angular.module('ui.bootstrap.carousel', [])
7474
return angular.isDefined(slide.index) ? +slide.index : slides.indexOf(slide);
7575
};
7676

77-
$scope.next = function() {
77+
self.next = $scope.next = function() {
7878
var newIndex = (self.getCurrentIndex() + 1) % slides.length;
7979

8080
if (newIndex === 0 && $scope.noWrap()) {
@@ -85,7 +85,7 @@ angular.module('ui.bootstrap.carousel', [])
8585
return self.select(getSlideByIndex(newIndex), 'next');
8686
};
8787

88-
$scope.prev = function() {
88+
self.prev = $scope.prev = function() {
8989
var newIndex = self.getCurrentIndex() - 1 < 0 ? slides.length - 1 : self.getCurrentIndex() - 1;
9090

9191
if ($scope.noWrap() && newIndex === slides.length - 1) {

src/carousel/test/carousel.spec.js

+8
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,14 @@ describe('carousel', function() {
436436
}
437437
});
438438

439+
it('should expose .next()', function() {
440+
expect(ctrl.next).toEqual(scope.next);
441+
});
442+
443+
it('should expose .prev()', function() {
444+
expect(ctrl.prev).toEqual(scope.prev);
445+
});
446+
439447
describe('addSlide', function() {
440448
it('should set first slide to active = true and the rest to false', function() {
441449
angular.forEach(ctrl.slides, function(slide, i) {

0 commit comments

Comments
 (0)