I'm attempting to recreate a jQuery plugin that I've created within AngularJS as a directive. I'm having a bit of an issue in regards to transclusion.
jQuery Widget plugin: http://plnkr.co/edit/xxZIb2DyAere7pBY6qm7?p=preview
AngularJS Directive: http://plnkr.co/edit/N6f5H8oZkpNy5jbVQPgj?p=preview
-
I have an array of users like:
[
{ name: 'intellix' }, { name: 'and' }, { name: 'konoro' }, { name: 'kingdom' }, { name: 'are' }, { name: 'awesome' },{ name: 'really!' }
]
And my jQuery widget chunks data so they're in 3 rows and slides them... the data gets transformed into chunks and put into their own containers like:
[
[
{ name: 'intellix' }, { name: 'and' }, { name: 'konoro' }
],
[
{ name: 'kingdom' }, { name: 'are' }, { name: 'awesome' }
],
[
{ name: 'really!' }
]
]
As a designer or anyone using this widget, they shouldn't have to chunk it themselves, that's what the widget/directive is supposed to be for and you should be able to have your own HTML... something like:
<flicker delay="1000">
<flicker-row ng-repeat="user in users">
<p>User: {{user.name}}</p>
</flicker-row>
</flicker>
The result I would want is:
<flicker delay="1000">
<div class="container">
<flicker-row>
<p>User: intellix</p>
</flicker-row>
<flicker-row>
<p>User: and</p>
</flicker-row>
<flicker-row>
<p>User: konoro</p>
</flicker-row>
</div>
<div class="container">
<flicker-row>
<p>User: kingdom</p>
</flicker-row>
<flicker-row>
<p>User: are</p>
</flicker-row>
<flicker-row>
<p>User: awesome</p>
</flicker-row>
</div>
<div class="container">
<flicker-row>
<p>User: really</p>
</flicker-row>
</div>
</flicker>
But ngTransclude
just takes the whole HTML it loops through and places it inside the flicker directive's template. I want to create 3 chunks in that directive, and then loop through those chunks, printing the HTML into those 3 containers.
How can I have transclude for creating a scope, but not have it just dump the whole result into the template?
I've attempted to chunk the data beforehand in my controller and have 2 controllers... but in my flicker-row directive the items haven't been looped through yet so I can't process them
<flicker delay="1000">
<flicker-row ng-repeat="users in userChunks">
<div class="item" ng-repeat="user in users">
<p>{{user.name}}</p>
</div>
</flicker-row>
</flicker>