在输出html可以由变量确定的意义上,我们的一些指令是动态的。例如
<div ng-repeat="m in arry">
<my-directive options="m.options"></my-directive>
</div>
然后myDirective
可以更改其输出html,例如m.options.template
目前我们只是使用巨型ng-switch
来处理此问题,
<div ng-switch="options.template">
<div ng-switch-when="richText"></div>
<div ng-switch-when="select"></div>
<div ng-switch-when="number"></div>
</div>
但开始注意到性能问题。
我认为更好的方法是根据m.options.template
本身的my-directive
插入html。出于性能原因,我想在compile
阶段执行此操作,但我无法访问范围,因此无法在链接之前确定m.options.template
的值。
最好的方法是什么?