So, AngularJs invalidates the Replace property of the directive. link
context:
.directive('myDir', function($compile) { return { restrict: 'E', template: '<div>{{title}}</div>' } });
it will be:
<my-dir> <div> some title </div> </my-dir>
So, Replace will replace <my-dir></my-dir> with template . What is equivalent these days? Or just use the directive with restrict: 'A' .
I created this:
.directive('myDir', function($compile) { return { restrict: 'E', template: '<div>{{title}}</div>', link: link }; function link(scope, iElem, IAttr, ctrl, transcludeFn) { var parent = iElem.parent(); var contents = iElem.html(); iElem.remove(); parent.append($compile(contents)(scope)); } });
which will output:
<div> some title </div>
source share