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

Commit 3c8f22e

Browse files
committed
fix(carousel): re-enable deprecated directives
- Re-implement deprecated directives - Re-expose `CarouselController` with deprecation notice
1 parent e7c5879 commit 3c8f22e

File tree

2 files changed

+40
-15
lines changed

2 files changed

+40
-15
lines changed

Diff for: src/carousel/carousel.js

+27-4
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,6 @@ angular.module('ui.bootstrap.carousel', [])
246246
*/
247247
.directive('uibCarousel', [function() {
248248
return {
249-
restrict: 'EA',
250249
transclude: true,
251250
replace: true,
252251
controller: 'UibCarouselController',
@@ -421,11 +420,24 @@ angular.module('ui.bootstrap.carousel')
421420

422421
.value('$carouselSuppressWarning', false)
423422

423+
.controller('CarouselController', ['$scope', '$element', '$controller', '$log', '$carouselSuppressWarning', function($scope, $element, $controller, $log, $carouselSuppressWarning) {
424+
if (!$carouselSuppressWarning) {
425+
$log.warn('CarouselController is now deprecated. Use UibCarouselController instead.');
426+
}
427+
428+
return $controller('UibCarouselController', {
429+
$scope: $scope,
430+
$element: $element
431+
});
432+
}])
433+
424434
.directive('carousel', ['$log', '$carouselSuppressWarning', function($log, $carouselSuppressWarning) {
425435
return {
426-
restrict: 'EA',
427436
transclude: true,
428437
replace: true,
438+
controller: 'CarouselController',
439+
controllerAs: 'carousel',
440+
require: 'carousel',
429441
templateUrl: function(element, attrs) {
430442
return attrs.templateUrl || 'template/carousel/carousel.html';
431443
},
@@ -445,8 +457,7 @@ angular.module('ui.bootstrap.carousel')
445457

446458
.directive('slide', ['$log', '$carouselSuppressWarning', function($log, $carouselSuppressWarning) {
447459
return {
448-
449-
restrict: 'EA',
460+
require: '^carousel',
450461
transclude: true,
451462
replace: true,
452463
templateUrl: function(element, attrs) {
@@ -461,6 +472,18 @@ angular.module('ui.bootstrap.carousel')
461472
if (!$carouselSuppressWarning) {
462473
$log.warn('slide is now deprecated. Use uib-slide instead.');
463474
}
475+
476+
carouselCtrl.addSlide(scope, element);
477+
//when the scope is destroyed then remove the slide from the current slides array
478+
scope.$on('$destroy', function() {
479+
carouselCtrl.removeSlide(scope);
480+
});
481+
482+
scope.$watch('active', function(active) {
483+
if (active) {
484+
carouselCtrl.select(scope);
485+
}
486+
});
464487
}
465488
};
466489
}]);

Diff for: src/carousel/test/carousel.spec.js

+13-11
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,6 @@ describe('carousel', function() {
340340
});
341341

342342
describe('slide order', function() {
343-
344343
beforeEach(function() {
345344
scope.slides = [
346345
{active:false,content:'one', id:1},
@@ -551,27 +550,30 @@ describe('carousel deprecation', function() {
551550
spyOn($log, 'warn');
552551

553552
var element = '<carousel interval="interval" no-transition="true" no-pause="nopause">' +
554-
'<slide ng-repeat="slide in slides" active="slide.active">' +
555-
'{{slide.content}}' +
556-
'</slide>' +
557-
'</carousel>';
553+
'<slide ng-repeat="slide in slides" active="slide.active">' +
554+
'{{slide.content}}' +
555+
'</slide>' +
556+
'</carousel>';
558557
element = $compile(element)($rootScope);
559558
$rootScope.$digest();
560559

561-
expect($log.warn.calls.count()).toBe(1);
562-
expect($log.warn.calls.argsFor(0)).toEqual(['carousel is now deprecated. Use uib-carousel instead.']);
560+
expect($log.warn.calls.count()).toBe(2);
561+
expect($log.warn.calls.argsFor(0)).toEqual(['CarouselController is now deprecated. Use UibCarouselController instead.']);
562+
expect($log.warn.calls.argsFor(1)).toEqual(['carousel is now deprecated. Use uib-carousel instead.']);
563563
}));
564564

565565
it('should give warning by default for slider', inject(function($compile, $log, $rootScope) {
566566
spyOn($log, 'warn');
567567

568568
var element = '<carousel interval="interval" no-transition="true" no-pause="nopause">' +
569-
'<slide></slide>' +
570-
'</carousel>';
569+
'<slide></slide>' +
570+
'</carousel>';
571571
element = $compile(element)($rootScope);
572572
$rootScope.$digest();
573573

574-
expect($log.warn.calls.count()).toBe(2);
575-
expect($log.warn.calls.argsFor(0)).toEqual(['slide is now deprecated. Use uib-slide instead.']);
574+
expect($log.warn.calls.count()).toBe(3);
575+
expect($log.warn.calls.argsFor(0)).toEqual(['CarouselController is now deprecated. Use UibCarouselController instead.']);
576+
expect($log.warn.calls.argsFor(1)).toEqual(['slide is now deprecated. Use uib-slide instead.']);
577+
expect($log.warn.calls.argsFor(2)).toEqual(['carousel is now deprecated. Use uib-carousel instead.']);
576578
}));
577579
});

0 commit comments

Comments
 (0)