Dynamically adding a directive from within a custom directive... when to compile?

237 views
Skip to first unread message

Tyler Young

unread,
Feb 19, 2013, 3:54:52 PM2/19/13
to ang...@googlegroups.com
Here's my sample code. I'm trying to figure out how to use a directive to be a "shortcut" for a few other directives. In this case it's dealing specifically with input elements, so transcluding the element in a wrapper template wouldn't get the job done.

From the documentation it seems that the $compile function is going to be what makes this all work. Either there aren't any examples of this, or there's a word I'm missing in my searches to make them come up. Has anyone else tried something like this? Is it just pure abuse of the framework?


Many thanks!

Peter Bacon Darwin

unread,
Feb 19, 2013, 4:24:39 PM2/19/13
to ang...@googlegroups.com


--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to angular+u...@googlegroups.com.
To post to this group, send email to ang...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular?hl=en-US.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Tyler Young

unread,
Feb 20, 2013, 12:25:00 PM2/20/13
to ang...@googlegroups.com
Thanks, Peter. If I'm understanding the gist of this correctly, it breaks down to these steps:
  1. The directive is creating a new DOM element with whatever modified directives are needed.
    1. "Modified" is inaccurate since it's just writing new ones.
  2. It then injects that new DOM element into the page after its own element.
  3. It removes its own element from the page.
Does that sound accurate? Is that the recommended solution for this type of problem?

I appreciate your help. Thanks for setting me straight on this!

Peter Bacon Darwin

unread,
Feb 20, 2013, 4:48:33 PM2/20/13
to ang...@googlegroups.com
Yes although you have to tread very carefully when it comes to "removing" the original element.  You are not really allowed to do this at compile or link time.
Reply all
Reply to author
Forward
0 new messages