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

Commit 9d5bc0a

Browse files
mvheckepkozlowski-opensource
authored andcommitted
refactor(carousel): use optional binding for 'active' attr in slides
Closes #1602
1 parent 0702403 commit 9d5bc0a

File tree

1 file changed

+3
-24
lines changed

1 file changed

+3
-24
lines changed

src/carousel/carousel.js

+3-24
Original file line numberDiff line numberDiff line change
@@ -297,38 +297,17 @@ function CarouselDemoCtrl($scope) {
297297
</example>
298298
*/
299299

300-
.directive('slide', ['$parse', function($parse) {
300+
.directive('slide', function() {
301301
return {
302302
require: '^carousel',
303303
restrict: 'EA',
304304
transclude: true,
305305
replace: true,
306306
templateUrl: 'template/carousel/slide.html',
307307
scope: {
308+
active: '=?'
308309
},
309310
link: function (scope, element, attrs, carouselCtrl) {
310-
//Set up optional 'active' = binding
311-
if (attrs.active) {
312-
var getActive = $parse(attrs.active);
313-
var setActive = getActive.assign;
314-
var lastValue = scope.active = getActive(scope.$parent);
315-
scope.$watch(function parentActiveWatch() {
316-
var parentActive = getActive(scope.$parent);
317-
318-
if (parentActive !== scope.active) {
319-
// we are out of sync and need to copy
320-
if (parentActive !== lastValue) {
321-
// parent changed and it has precedence
322-
lastValue = scope.active = parentActive;
323-
} else {
324-
// if the parent can be assigned then do so
325-
setActive(scope.$parent, parentActive = lastValue = scope.active);
326-
}
327-
}
328-
return parentActive;
329-
});
330-
}
331-
332311
carouselCtrl.addSlide(scope, element);
333312
//when the scope is destroyed then remove the slide from the current slides array
334313
scope.$on('$destroy', function() {
@@ -342,4 +321,4 @@ function CarouselDemoCtrl($scope) {
342321
});
343322
}
344323
};
345-
}]);
324+
});

0 commit comments

Comments
 (0)