Skip to content

Instantly share code, notes, and snippets.

@bramus
Forked from amatiasq/mq-allow-external-clone.js
Last active September 8, 2015 20:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bramus/436039fb314a365f73b5 to your computer and use it in GitHub Desktop.
Save bramus/436039fb314a365f73b5 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