Add directives from directive in AngularJS

后端 未结 7 1695
庸人自扰
庸人自扰 2020-11-22 10:02

I\'m trying to build a directive that takes care of adding more directives to the element it is declared on. For example, I want to build a directive that t

7条回答
  •  误落风尘
    2020-11-22 10:07

    You can actually handle all of this with just a simple template tag. See http://jsfiddle.net/m4ve9/ for an example. Note that I actually didn't need a compile or link property on the super-directive definition.

    During the compilation process, Angular pulls in the template values before compiling, so you can attach any further directives there and Angular will take care of it for you.

    If this is a super directive that needs to preserve the original internal content, you can use transclude : true and replace the inside with

    Hope that helps, let me know if anything is unclear

    Alex

提交回复
热议问题