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

Commit 30e8aa7

Browse files
committed
fix(carousel): re-enable deprecated directives
- Re-implement deprecated directives - Re-expose `CarouselController` with deprecation notice Closes #4527
1 parent 6b4267b commit 30e8aa7

File tree

2 files changed

+40
-15
lines changed

2 files changed

+40
-15
lines changed

src/carousel/carousel.js

+27-4
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,6 @@ angular.module('ui.bootstrap.carousel', [])
253253
*/
254254
.directive('uibCarousel', [function() {
255255
return {
256-
restrict: 'EA',
257256
transclude: true,
258257
replace: true,
259258
controller: 'UibCarouselController',
@@ -428,11 +427,24 @@ angular.module('ui.bootstrap.carousel')
428427

429428
.value('$carouselSuppressWarning', false)
430429

430+
.controller('CarouselController', ['$scope', '$element', '$controller', '$log', '$carouselSuppressWarning', function($scope, $element, $controller, $log, $carouselSuppressWarning) {
431+
if (!$carouselSuppressWarning) {
432+
$log.warn('CarouselController is now deprecated. Use UibCarouselController instead.');
433+
}
434+
435+
return $controller('UibCarouselController', {
436+
$scope: $scope,
437+
$element: $element
438+
});
439+
}])
440+
431441
.directive('carousel', ['$log', '$carouselSuppressWarning', function($log, $carouselSuppressWarning) {
432442
return {
433-
restrict: 'EA',
434443
transclude: true,
435444
replace: true,
445+
controller: 'CarouselController',
446+
controllerAs: 'carousel',
447+
require: 'carousel',
436448
templateUrl: function(element, attrs) {
437449
return attrs.templateUrl || 'template/carousel/carousel.html';
438450
},
@@ -452,8 +464,7 @@ angular.module('ui.bootstrap.carousel')
452464

453465
.directive('slide', ['$log', '$carouselSuppressWarning', function($log, $carouselSuppressWarning) {
454466
return {
455-
456-
restrict: 'EA',
467+
require: '^carousel',
457468
transclude: true,
458469
replace: true,
459470
templateUrl: function(element, attrs) {
@@ -468,6 +479,18 @@ angular.module('ui.bootstrap.carousel')
468479
if (!$carouselSuppressWarning) {
469480
$log.warn('slide is now deprecated. Use uib-slide instead.');
470481
}
482+
483+
carouselCtrl.addSlide(scope, element);
484+
//when the scope is destroyed then remove the slide from the current slides array
485+
scope.$on('$destroy', function() {
486+
carouselCtrl.removeSlide(scope);
487+
});
488+
489+
scope.$watch('active', function(active) {
490+
if (active) {
491+
carouselCtrl.select(scope);
492+
}
493+
});
471494
}
472495
};
473496
}]);

src/carousel/test/carousel.spec.js

+13-11
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,6 @@ describe('carousel', function() {
355355
});
356356

357357
describe('slide order', function() {
358-
359358
beforeEach(function() {
360359
scope.slides = [
361360
{active:false,content:'one', id:1},
@@ -566,27 +565,30 @@ describe('carousel deprecation', function() {
566565
spyOn($log, 'warn');
567566

568567
var element = '<carousel interval="interval" no-transition="true" no-pause="nopause">' +
569-
'<slide ng-repeat="slide in slides" active="slide.active">' +
570-
'{{slide.content}}' +
571-
'</slide>' +
572-
'</carousel>';
568+
'<slide ng-repeat="slide in slides" active="slide.active">' +
569+
'{{slide.content}}' +
570+
'</slide>' +
571+
'</carousel>';
573572
element = $compile(element)($rootScope);
574573
$rootScope.$digest();
575574

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

580580
it('should give warning by default for slider', inject(function($compile, $log, $rootScope) {
581581
spyOn($log, 'warn');
582582

583583
var element = '<carousel interval="interval" no-transition="true" no-pause="nopause">' +
584-
'<slide></slide>' +
585-
'</carousel>';
584+
'<slide></slide>' +
585+
'</carousel>';
586586
element = $compile(element)($rootScope);
587587
$rootScope.$digest();
588588

589-
expect($log.warn.calls.count()).toBe(2);
590-
expect($log.warn.calls.argsFor(0)).toEqual(['slide is now deprecated. Use uib-slide instead.']);
589+
expect($log.warn.calls.count()).toBe(3);
590+
expect($log.warn.calls.argsFor(0)).toEqual(['CarouselController is now deprecated. Use UibCarouselController instead.']);
591+
expect($log.warn.calls.argsFor(1)).toEqual(['slide is now deprecated. Use uib-slide instead.']);
592+
expect($log.warn.calls.argsFor(2)).toEqual(['carousel is now deprecated. Use uib-carousel instead.']);
591593
}));
592594
});

0 commit comments

Comments
 (0)