AngularJS - how to have a directive with a dynamic sub-directive

后端 未结 2 877
面向向阳花
面向向阳花 2020-12-09 12:36

Really struggling with this - have tried every way I can think of. Hopefully, somebody can help.

I have a directive which creates the outline of a custom control fo

相关标签:
2条回答
  • 2020-12-09 13:00

    Try this fiddle http://jsfiddle.net/xpKwb/12/

    You can use ngSwitch

    <div ng-repeat='template in inner'>
        <div ng-switch on="template">
            <div ng-switch-when="one">
                <div class='one'></div>
            </div>
            <div ng-switch-when="two">
                <div class='two'></div>
    
            </div>
        </div>
    
    0 讨论(0)
  • 2020-12-09 13:06

    I have create a fiddle here.

    These are the directives.

    <script type="text/ng-template" id="one">
        <div class="one"></div>
    </script>
    <script type="text/ng-template" id="two">
         <div class="two"></div>
    </script>
    

    And here you do dynamic loading

    <div ng-repeat='template in inner' ng-include='template'></div>
    

    See if this helps you, and solves your purpose. I am making each directive into a template and then using ng include

    0 讨论(0)
提交回复
热议问题