Angular directive for slick-carousel
- Singlemost improvement which triggered the development of this release: the
$timeout
in v1.0 was working but arbitrary. We now register a simpleonFinishRender
directive which allows us to postpone slickification untilng-repeat
has finished execution. - [BC-BREAK] The directive is no longer based on a transclude functionality. You can either use the 2.0
directive with the provided template or use your own (when using the
src
attribute). - [BC-BREAK] The directive no longer supports statically provided image assets out-of-the-box. The dynamic usecase is what it tries to solve optimally.
- You should now use JS to specify a variety of sources in the
media
array. See example.
This directive allows you to use the slick-carousel plugin as
an angular directive. It can be specified in your HTML
as either a <div>
attribute or a <slick>
element.
<slick settings="scoped-settings"
control="scoped-control-handle"
media="media"
src="optionalCustomTemplate.html"
on-directive-init="onDirectiveInit()"
is-image="isImage(media)"
is-video="isVideo(media)>
</slick>
settings
: optionalObject
containing any of the slick options. Consult here.control
: optionalObject
discussed below in detailmedia
: mandatoryArray
of images and/or videosrc
: optionalString
the url for the custom template, if desiredon-directive-init
: optionalFunction
the directive's handle object is ready to use in this function. This is different fromslick
'sonInit
handler.is-image
: optionalFunction
that takes a metadata object and returns aBoolean
is-video
: optionalFunction
that takes a metadata object and returns aBoolean
- Include the
slick.js
at the base of this repo, or install throughbower
:
bower install angular-slick-carousel
- Add it to your HTML using usual
<script>
tags. - In your angular app definition, define
bardo.directives
as a dependency.
angular.module('slickExampleApp', ['bardo.directives'])
- That should be it. Now, you can specify the usual
options to the carousel plugin using either a JavaScript
settings
object onscope
, or asdata-<setting-name>
attributes in the HTML tag itself. Note that specifyingdata-
prefixed names helps avoid issues with camel-cased settings options.
- All the functions in the plugin are exposed through a control attribute.
- To utilize this architecture, and have two-way data-binding, define an empty control handle on scope:
$scope.slickHandle = {
};
- Pass it as the value to control attribute. Now, you can call any plugin methods as shown in the example.
<button ng-click="slickHandle.slickGoTo(2)">slickGoTo(2)</button>
<button ng-click="slickHandle.slickPrev()">slickPrev()</button>
<button ng-click="slickHandle.slickNext()">slickNext()</button>
<button ng-click='slickHandle.slickAdd("<div>New</div>")'>slickAdd()</button>
<button ng-click='slickHandle.slickRemove(3)'>slickRemove(3)</button>
<button ng-click='slickHandle.slickPlay()'>slickPlay()</button>
<button ng-click='slickHandle.slickPause()'>slickPause()</button>