Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple transclusions of separate html

Tags:

html

angularjs

I'd like to transclude multiple pieces into one directive. Here is my idea of how I'd set it up.

<div id="content" class="mainDirective">
    <div class="sub">
        <ul>
            <li>Everyone</li>
            <li>Development (3)</li>
            <li>Marketing</li>
        </ul>
    </div>
    <div class="subButtons">
        <span class="csStIcon add" data-ng-click="addTeam()"></span>
        <span class="csStIcon edit" data-ng-click="editTeam()"></span>
        <span class="csStIcon delete" data-ng-click="deleteTeam()"></span>
    </div>
    <div class="main">
        <table>
            <thead>
                <tr><td>Name</td><td>Last name</td><td>Department</td></tr>
            </thead>
            <tbody>
                <tr><td>Lorem</td><td>Ipsum</td><td>Development</td></tr>
                <tr><td>Lorem</td><td>Ipsum</td><td>Development</td></tr>
                <tr><td>Lorem</td><td>Ipsum</td><td>Development</td></tr>
            </tbody>
        </table>
    </div>
</div>

My directive template:

<div>
    <div class="left">
        <div data-ng-multi-transclude="sub"></div>
        <div class="bottomOptions">
            <span class="csStIcon collapse"></span>
            <div data-ng-multi-transclude="subButtons"></div>
        </div>
    </div>
    <div class="right">
        <div data-ng-multi-transclude="main"></div>
    </div>
</div>

And the final output:

<div>
    <div class="left">
        <div class="sub">
            <ul>
                <li>Everyone</li>
                <li data-ng-click="loadDepartment()">Development (3)</li>
                <li data-ng-click="loadDepartment()">Marketing</li>
            </ul>
        </div>
        <div class="bottomOptions">
            <span class="csStIcon collapse"></span>
            <div class="subButtons">
                <div class="subButtons">
                    <span class="csStIcon add" data-ng-click="addTeam()"></span>
                    <span class="csStIcon edit" data-ng-click="editTeam()"></span>
                    <span class="csStIcon delete" data-ng-click="deleteTeam()"></span>
                </div>              
            </div>
        </div>
    </div>
    <div class="right">
        <div class="main">
            <table>
                <thead>
                    <tr><td>Name</td><td>Last name</td><td>Department</td></tr>
                </thead>
                <tbody>
                    <tr><td>Lorem</td><td>Ipsum</td><td>Development</td></tr>
                    <tr><td>Lorem</td><td>Ipsum</td><td>Development</td></tr>
                    <tr><td>Lorem</td><td>Ipsum</td><td>Development</td></tr>
                </tbody>
            </table>
        </div>
    </div>
</div>

Is this possible within angular?

like image 689
Mathew Berg Avatar asked Nov 04 '22 05:11

Mathew Berg


1 Answers

I ended up needing this functionality as well, so I wrote ng-multi-transclude -- funnily enough, I hadn't seen this question at the time, just lucked into the same name.

Usage is almost exactly as your question sketches; the only difference is that you use the name attribute to pick the "hole" to fill instead of the class attribute.

like image 129
Zach Snow Avatar answered Nov 08 '22 04:11

Zach Snow