在Angular中创建递归有两种方法:
第一种方法使用$compile函数并手动编译内容。
compile: function(tElement, tAttr) {
var contents = tElement.contents().remove();
var compiledContents;
return function(scope, iElement, iAttr) {
if(!compiledContents) {
compiledContents = $compile(contents);
}
compiledContents(scope, function(clone, scope) {
iElement.append(clone);
});
};
},
第二个使用ng-include
链接:https://groups.google.com/forum/?fromgroups=#!topic/angular/TbpjE-5XEM0
<script type="text/ng-template" id="tree_item_renderer.html">
例子:http://jsfiddle.net/brendanowen/uXbn6/8/
我的问题是:它们各自有什么优缺点?是否可能在ng-include中使用包含自定义指令的模板?