Reputation: 14258
I wish to write a directive that basically transforms this:
<g:text>Hello There</g:text>
to
<svg class="gx-text"><text>Hello There</text></svg>
so that in the dom, the <g:text>
element has been completely replaced by the <svg>
element
I don't want to use ng-transclude as I found that it added a bunch of other elements to the dom.
Upvotes: 3
Views: 426
Reputation: 364697
var app = angular.module('app', []);
app.directive('gText', function() {
return {
restrict: 'E',
compile: function(tElement, attrs) {
tElement.replaceWith('<svg class="gx-text"><text>'
+ tElement.text() + '</text></svg>');
}
}
});
Upvotes: 4