Reputation: 7951
Suppose I have a directive named my-directive
.
How do I access or manipulate the text between the directive tags in the directive code, like this:
<my-directive> Custom Text <my-directive>
And my directive code:
app.directive('myDirective', function() {
return {
...
template: '<div>...Custom Text somewhere inside div... </div>'
};
);
Upvotes: 3
Views: 4867
Reputation: 5254
Use the ng-transclude
directive in your template.
.directive('myDirective', function() {
return {
transclude: true,
template: '<div><ng-transclude></ng-transclude></div>
}
});
Moves the previous inner content to where the ng-transclude is in the template.
Upvotes: 15
Reputation: 1485
if you give template in your directive. it will replace the text inside the html
app.directive('myDirective', function() {
return {
restrict: 'E',
compile: function(elem) {
elem.replaceWith(markdown.toHTML(elem.html()));
}
}
});
Upvotes: 0