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

Commit dac087e

Browse files
committed
feat(carousel): add model binding support to slide
- Add support for binding slide model to slide Closes #4202 Resolves #4201
1 parent 3d01c59 commit dac087e

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

src/carousel/carousel.js

+1
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,7 @@ function CarouselDemoCtrl($scope) {
316316
},
317317
scope: {
318318
active: '=?',
319+
actual: '=?',
319320
index: '=?'
320321
},
321322
link: function (scope, element, attrs, carouselCtrl) {

src/carousel/docs/README.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ The carousel also offers support for touchscreen devices in the form of swiping.
44

55
Use a `<carousel>` element with `<slide>` elements inside it. It will automatically cycle through the slides at a given rate, and a current-index variable will be kept in sync with the currently visible slide.
66

7-
Use the `no-wrap` attribute on a `<carousel>` element to control the looping of slides; setting `no-wrap` to an expression which evaluates to a truthy value will prevent looping
7+
Use the `no-wrap` attribute on a `<carousel>` element to control the looping of slides; setting `no-wrap` to an expression which evaluates to a truthy value will prevent looping.
88

9-
Use the `template-url` attribute on a `<carousel>` or `<slide>` element to specify the url of a custom template to override the default templates
9+
Use the `template-url` attribute on a `<carousel>` or `<slide>` element to specify the url of a custom template to override the default templates.
10+
11+
Use the `actual` attribute on a `<slide>` element to bind the slide model (or any object of interest) onto the slide directive's `$scope`, which makes it available for customization in the carousel template.

src/carousel/test/carousel.spec.js

+23
Original file line numberDiff line numberDiff line change
@@ -499,4 +499,27 @@ describe('carousel', function() {
499499
expect(elm.html()).toBe('foo');
500500
}));
501501
});
502+
503+
it('should expose a custom model in the carousel slide', function() {
504+
var scope = $rootScope.$new();
505+
scope.slides = [
506+
{active:false,content:'one'},
507+
{active:false,content:'two'},
508+
{active:false,content:'three'}
509+
];
510+
var elm = $compile(
511+
'<carousel interval="interval" no-transition="true" no-pause="nopause">' +
512+
'<slide ng-repeat="slide in slides" active="slide.active" actual="slide">' +
513+
'{{slide.content}}' +
514+
'</slide>' +
515+
'</carousel>'
516+
)(scope);
517+
$rootScope.$digest();
518+
519+
var ctrl = elm.controller('carousel');
520+
521+
expect(angular.equals(ctrl.slides.map(function(slide) {
522+
return slide.actual;
523+
}), scope.slides)).toBe(true);
524+
});
502525
});

0 commit comments

Comments
 (0)