Skip to content

Commit

Permalink
Merge pull request #13 from benjamincharity/fallback-to-element-id-12
Browse files Browse the repository at this point in the history
Fallback to element id 12
  • Loading branch information
benjamincharity committed Feb 20, 2016
2 parents 303bcfb + c8ceb43 commit 7e78aeb
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 13 deletions.
23 changes: 16 additions & 7 deletions dist/angular-flickity.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/angular-flickity.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/angular-flickity.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/angular-flickity.min.js.map

Large diffs are not rendered by default.

15 changes: 12 additions & 3 deletions src/flickity.directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export function FlickityDirective(
scope: {},
bindToController: {
bcFlickity: '@?',
bcFlickityId: '@?',
},
link: linkFunction,
controller: FlickityController,
Expand All @@ -39,21 +40,29 @@ export function FlickityDirective(
function linkFunction($scope, $element, $attrs, $controller) {
'ngInject';

// If no ID was passed in
if (!$controller.bcFlickityId) {
// Use the element's ID if one exists
if ($attrs.id) {
$controller.bcFlickityId = $attrs.id;
}
}

// Using a timeout ensures that any ng-repeats can finish running before we initialize
$timeout(() => {
// Initialize Flickity
const flickityInstance =
FlickityService.create($element[0], $controller.flickityId, $controller.options);
FlickityService.create($element[0], $controller.bcFlickityId, $controller.options);

// Expose the Flickity instance and ID
$controller.Flickity = flickityInstance.instance;
$controller.flickityId = flickityInstance.id;
$controller.bcFlickityId = flickityInstance.id;
});


// Clean up when being destroyed
const onDestroy = $scope.$on('$destroy', (event) => {
FlickityService.destroy($controller.flickityId);
FlickityService.destroy($controller.bcFlickityId);
});

}
Expand Down

0 comments on commit 7e78aeb

Please sign in to comment.