2

This is probably as basic as it gets. I have some simple markup that's suppose to represent a list:

<unordered-list>
    <list-item></list-item>
    <list-item></list-item>
</unordered-list>

I also have two directives defined for unordered-list and list-item:

.directive('unorderedList', function() {
    return {
        restrict: 'E',
        replace: true,
        template: '<ul></ul>'
    };
})
.directive('listItem', function() {
    return {
        restrict: 'E',
        replace: true,
        template: '<li>Test</li>'
    }
});

Yet when I run this (http://jsfiddle.net/esWUD/), the only thing rendered is the <ul>. No <li>Test</li> elements render within the <ul>.

Why not don't they render?

1 Answer 1

2

You'll need to use ngTransclude to allow directives to have sub-elements. Set transclude: true in unorderedList.

    transclude: true,
    template: '<ul ng-transclude></ul>'

Working fiddle.

Sign up to request clarification or add additional context in comments.

2 Comments

I tried transclude: true without ng-transclude in the template and it didn't work. Does one always have to include ng-transclude in the template when they've already specified transclude: true?
Yes, as far as I know. It can be bothersome, but gives greater control: you can have more complex templates, with a <div ng-transclude></div> somewhere in the template. I would personally love to see it working as we both initially expected.

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.