So AngularJs
are deprecating the Replace
property of a directive. reference
context:
.directive('myDir', function($compile) {
return {
restrict: 'E',
template: '<div>{{title}}</div>'
}
});
this will ouput:
<my-dir>
<div> some title </div>
</my-dir>
So, Replace
would replace <my-dir></my-dir>
with the template
. What is the equivalent these days? Or is it just to use a 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>