Skip to content

Instantly share code, notes, and snippets.

@amatiasq
Created May 28, 2015 09:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save amatiasq/ae6fce9acf74589ef36d to your computer and use it in GitHub Desktop.
Save amatiasq/ae6fce9acf74589ef36d to your computer and use it in GitHub Desktop.
Directive to allow 3rd party libraries to clone angular nodes.
angular.module('my-module')
.directive('mqAllowExternalClone', function($compile) {
return {
link: link,
};
function link(scope, elem, attr) {
var element = elem[0];
var original = element.cloneNode;
element.cloneNode = patch;
function patch(deep) {
var clone = original.call(element, deep);
// You can remove this two lines and the result
// will be more or less the same.
// In my case I need it for other reasons
clone.removeAttribute('mq-allow-external-clone');
clone.cloneNode = patch;
$compile(clone)(scope);
return clone;
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment