0

I have created a directive called first. Like below

 <div first>
        <p>aaaaaa11111</p>
</div>

angular js like

var testdirective = angular.module("testdirective",[]);

testdirective.directive('first', function()
{
    return
    {
        transclude: true,
        template: '<div> This is my directive content</div>'
    }
});

on running the file "

aaaaaa11111

" content is not showing y.....

2 Answers 2

2

You are using the wrong template (api ref).

template: '<div> This is my directive content <ng-transclude></ng-transclude></div>'
Sign up to request clarification or add additional context in comments.

Comments

1

You are not using ng-trasclude directive into your template. Here is update code:

HTML:

<div ng-app="testdirective">
    <div first>
        <p>aaaaaa11111</p>
    </div>
</div>

JavaScript

var testdirective = angular.module("testdirective",[]);
testdirective.directive('first', function() {
    return {
        transclude: true,
        template: '<div> This is my directive content<span ng-transclude></span></div>'
    }
});

You can checkout JSFiddle link. Its having running demo.

For more details you can checkout blog http://codechutney.in/blog/angularjs/transclude-in-angularjs/.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.