I am trying to simplify the code below, which is inside angular controller, dynamically adds attribute and recompiles directive inner html.
additionalInfo: '=',
This attribute enables parts of the code in a template, so it must be recompiled while being dynamically created
$element.attr('additional-info', "'test'");
var template = angular.element('<a></a>').append($element.clone()).html();
$element.replaceWith($compile(template)($scope.$parent));
The code works fine, I am trying to distill the code to minimum, any thoughts? Maybe something can be replaced to look nicer?
I have got two more options, which yield the same result:
var template = angular.element('<a></a>').append($element.clone()).html();
var template = $element.get(0).outerHTML;
var template = $element.html($element.get(0).cloneNode(true));
All of them work correctly, but the last one is actually returning an object, but this still works? How? Why? Pros/Cons?