Text between directive tags

angularjs

Solution

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.

Demo in Plunker

Problem

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>' }; ); ```

Original source

Related problems