diff --git a/src/carousel/carousel.js b/src/carousel/carousel.js index 0ba813dc01..a5a2a4afde 100644 --- a/src/carousel/carousel.js +++ b/src/carousel/carousel.js @@ -253,7 +253,6 @@ angular.module('ui.bootstrap.carousel', []) */ .directive('uibCarousel', [function() { return { - restrict: 'EA', transclude: true, replace: true, controller: 'UibCarouselController', @@ -428,11 +427,24 @@ angular.module('ui.bootstrap.carousel') .value('$carouselSuppressWarning', false) +.controller('CarouselController', ['$scope', '$element', '$controller', '$log', '$carouselSuppressWarning', function($scope, $element, $controller, $log, $carouselSuppressWarning) { + if (!$carouselSuppressWarning) { + $log.warn('CarouselController is now deprecated. Use UibCarouselController instead.'); + } + + return $controller('UibCarouselController', { + $scope: $scope, + $element: $element + }); +}]) + .directive('carousel', ['$log', '$carouselSuppressWarning', function($log, $carouselSuppressWarning) { return { - restrict: 'EA', transclude: true, replace: true, + controller: 'CarouselController', + controllerAs: 'carousel', + require: 'carousel', templateUrl: function(element, attrs) { return attrs.templateUrl || 'template/carousel/carousel.html'; }, @@ -452,8 +464,7 @@ angular.module('ui.bootstrap.carousel') .directive('slide', ['$log', '$carouselSuppressWarning', function($log, $carouselSuppressWarning) { return { - - restrict: 'EA', + require: '^carousel', transclude: true, replace: true, templateUrl: function(element, attrs) { @@ -468,6 +479,18 @@ angular.module('ui.bootstrap.carousel') if (!$carouselSuppressWarning) { $log.warn('slide is now deprecated. Use uib-slide instead.'); } + + carouselCtrl.addSlide(scope, element); + //when the scope is destroyed then remove the slide from the current slides array + scope.$on('$destroy', function() { + carouselCtrl.removeSlide(scope); + }); + + scope.$watch('active', function(active) { + if (active) { + carouselCtrl.select(scope); + } + }); } }; }]); \ No newline at end of file diff --git a/src/carousel/test/carousel.spec.js b/src/carousel/test/carousel.spec.js index 37a6017eea..adb9c76ecc 100644 --- a/src/carousel/test/carousel.spec.js +++ b/src/carousel/test/carousel.spec.js @@ -355,7 +355,6 @@ describe('carousel', function() { }); describe('slide order', function() { - beforeEach(function() { scope.slides = [ {active:false,content:'one', id:1}, @@ -566,27 +565,30 @@ describe('carousel deprecation', function() { spyOn($log, 'warn'); var element = '' + - '' + - '{{slide.content}}' + - '' + - ''; + '' + + '{{slide.content}}' + + '' + + ''; element = $compile(element)($rootScope); $rootScope.$digest(); - expect($log.warn.calls.count()).toBe(1); - expect($log.warn.calls.argsFor(0)).toEqual(['carousel is now deprecated. Use uib-carousel instead.']); + expect($log.warn.calls.count()).toBe(2); + expect($log.warn.calls.argsFor(0)).toEqual(['CarouselController is now deprecated. Use UibCarouselController instead.']); + expect($log.warn.calls.argsFor(1)).toEqual(['carousel is now deprecated. Use uib-carousel instead.']); })); it('should give warning by default for slider', inject(function($compile, $log, $rootScope) { spyOn($log, 'warn'); var element = '' + - '' + - ''; + '' + + ''; element = $compile(element)($rootScope); $rootScope.$digest(); - expect($log.warn.calls.count()).toBe(2); - expect($log.warn.calls.argsFor(0)).toEqual(['slide is now deprecated. Use uib-slide instead.']); + expect($log.warn.calls.count()).toBe(3); + expect($log.warn.calls.argsFor(0)).toEqual(['CarouselController is now deprecated. Use UibCarouselController instead.']); + expect($log.warn.calls.argsFor(1)).toEqual(['slide is now deprecated. Use uib-slide instead.']); + expect($log.warn.calls.argsFor(2)).toEqual(['carousel is now deprecated. Use uib-carousel instead.']); })); });