AngularJS and $compile May 15, 2013 in Development 4 Comments on this post. Josh I wrote a quick example to demonstrate how you can do this. http://jsfiddle.net/jec006/sSw2M/ Michael Thanks for the example Josh! it works Great. I was wondering if whether the directives are defined in different modules might have an impact on the success of your solution. (It’s not working for me). Josh Hi Micheal, You can definitely declare the directives in different modules, you just need to make sure that the original app / controller etc includes that module. Something like: angular.module(‘myModule’, ['mySecondModule']); Hope that helps. Simon Hi Josh, thanks for your article! I am using a compile-function but discover problems when I want to remove the compiled element again. The DOM and the connected data is not cleaned up correctly what leads to a memory leak. How do I remove elements that I compiled and linked using $compile?