From the directive Angular docs, I see the compile function has 3 parameters, one of which is transclude. The only explanation the docs provide is:
transclude – A transclude linking function: function(scope, cloneLinkingFn).
I’m trying to understand what exactly you would do in the clone linking function. I don’t even know what parameters get passed into it. I found one example that has one parameter called clone that appears to be an HTML element. Are there other parameters available? Which HTML element is this exactly? I’m also looking at probably using transclude: 'element' in my directive. Do the answers to those questions change when using 'element' instead of true?
I’m understanding transclusion with the simple examples, but I can’t to seem to find more complex examples, especially with transclude: 'element'. I’m hoping someone can provide a more thorough explanation about all this. Thanks.
EDIT: Completely and totally changing my answer and marking this as “Community Wiki” (meaning no points for me) as I was outright wrong when I answered this
As @Jonah pointed out below, here is a really good article on the compile option of directives and using the transclusion function
The basic idea is the compile function should return a linking function. You can use the transclusion function provided inside the linking function to take a clone of the transcluded DOM element, compile it, and insert it wherever it needs to be inserted.
Here is a better example I’ve pulled out of my butt on Plunker
The idea of the compile function is it gives you a chance to programmatically alter the DOM elements based on attributes passed BEFORE the linking function is created and called.