Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8772423
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T18:01:39+00:00 2026-06-13T18:01:39+00:00

From the directive Angular docs , I see the compile function has 3 parameters,

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T18:01:41+00:00Added an answer on June 13, 2026 at 6:01 pm

    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.

    // a silly directive to repeat the items of a dictionary object.
    app.directive('keyValueRepeat', function ($compile){
      return {
        transclude: true,
        scope: {
          data: '=',
          showDebug: '@'
        },
        compile: function(elem, attrs, transclude) {
    
          if(attrs.showDebug) {                
            elem.append('<div class="debug">DEBUG ENABLED {{showDebug}}</div>');
          }
    
          return function(scope, lElem, lAttrs) {
            var items = [];
            console.log(lElem);
            scope.$watch('data', function(data) {
    
              // remove old values from the tracking array
              // (see below)
              for(var i = items.length; i-- > 0;) {
                items[i].element.remove();
                items[i].scope.$destroy();
                items.splice(i,1);
              }
    
              //add new ones
              for(var key in data) {
    
                var val = data[key],
                    childScope = scope.$new(),
                    childElement = angular.element('<div></div>');
    
                // for each item in our repeater, we're going to create it's
                // own scope and set the key and value properties on it.
                childScope.key = key;
                childScope.value = val;
    
                // do the transclusion.
                transclude(childScope, function(clone, innerScope) {
                  //clone is a copy of the transcluded DOM element content.
                  console.log(clone);
    
                  // Because we're still inside the compile function of the directive,
                  // we can alter the contents of each output item
                  // based on an attribute passed.
                  if(attrs.showDebug) {                
                    clone.prepend('<span class="debug">{{key}}: {{value}}</span>');
                  }
    
                  //append the transcluded element.
                  childElement.append($compile(clone)(innerScope));
                });
    
                // add the objects made to a tracking array.
                // so we can remove them later when we need to update.
                items.push({
                  element: childElement,
                  scope: childScope
                });
    
                lElem.append(childElement);
              }
            });
          };
        }
      };
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

From the Scala API , I got the following example, which does not compile;
I have a directive like the one of the examples from AngularJS, shown below.
From my website, I have a button which calls a method and then generates
I want to extract MasterPage value directive from a view page. I want the
I have several TextBoxes, which display angular values. I format these using different custom
i ve a function which is responsible for some validations, disabling and enabling of
Head First book says about include directive as include code from any other file
I am trying to rewrite url from www.xxx.com/test.com to www.xxx.com/my.php?d=test.com using the following directive:
From: RewriteBase Apache Docs # /abc/def/.htaccess -- per-dir config file for directory /abc/def #
It's my first try using the @if control directive from SASS . I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.