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

feat(carousel): add model binding support to slide #4202

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/carousel/carousel.js
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ function CarouselDemoCtrl($scope) {
},
scope: {
active: '=?',
actual: '=?',
index: '=?'
},
link: function (scope, element, attrs, carouselCtrl) {
Expand Down
6 changes: 4 additions & 2 deletions src/carousel/docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ The carousel also offers support for touchscreen devices in the form of swiping.

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.

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
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.

Use the `template-url` attribute on a `<carousel>` or `<slide>` element to specify the url of a custom template to override the default templates
Use the `template-url` attribute on a `<carousel>` or `<slide>` element to specify the url of a custom template to override the default templates.

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.
23 changes: 23 additions & 0 deletions src/carousel/test/carousel.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -499,4 +499,27 @@ describe('carousel', function() {
expect(elm.html()).toBe('foo');
}));
});

it('should expose a custom model in the carousel slide', function() {
var scope = $rootScope.$new();
scope.slides = [
{active:false,content:'one'},
{active:false,content:'two'},
{active:false,content:'three'}
];
var elm = $compile(
'<carousel interval="interval" no-transition="true" no-pause="nopause">' +
'<slide ng-repeat="slide in slides" active="slide.active" actual="slide">' +
'{{slide.content}}' +
'</slide>' +
'</carousel>'
)(scope);
$rootScope.$digest();

var ctrl = elm.controller('carousel');

expect(angular.equals(ctrl.slides.map(function(slide) {
return slide.actual;
}), scope.slides)).toBe(true);
});
});