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

Commit

Permalink
feat(carousel): add model binding support to slide
Browse files Browse the repository at this point in the history
- Add support for binding slide model to slide

Closes #4202
Resolves #4201
  • Loading branch information
wesleycho committed Aug 18, 2015
1 parent 3d01c59 commit dac087e
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
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);
});
});

0 comments on commit dac087e

Please sign in to comment.