Angular Recursion
Angular Recursion
有两种方法可以在angular
中创建递归第一个使用$compile函数并手动编译内容
链接:Angularjs:理解递归指令
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);
});
};
},
示例:http://jsfiddle.net/n8dPm/
第二个使用ng-include
链接:https://groups.google.com/forum/?fromgroups= # !主题/角度/TbpjE-5XEM0
<script type="text/ng-template" id="tree_item_renderer.html">
{{data.name}}
<button ng-click="add(data)">Add node</button>
<button ng-click="delete(data)" ng-show="data.nodes.length > 0">Delete nodes</button>
<ul>
<li ng-repeat="data in data.nodes" ng-include="'tree_item_renderer.html'"></li>
</ul>
示例:http://jsfiddle.net/brendanowen/uXbn6/8/
我的问题是:这两种方法的优缺点是什么是否可以在ng-include中使用包含自定义指令的模板?
我相信你错过了两个有价值的选择。
- 在指令的模板中使用自定义指令(是的,你可以这样做)
- 使用transclusion (https://egghead.io/lessons/angularjs-transclusion-basics)让模板的一部分在使用指令时可配置。实际上,这和第一个例子做的一样,但是更简单。
相关文章:
- Angular JS IE9 Hashbang url rewriting
- 如何使用skip参数使用angular ui引导进行服务器端分页
- 在自定义mean.io包中使用angular-chart.js作为依赖项
- 无法在数据endVal中设置值=“”;{{ucount}}”;使用Angular JS的CountUp
- 使用angular重定向到html页面
- angular.js没有'无法在PhoneGap中处理视图标记
- Javascript(Angular)从一个对象数组到第二个数组查找值
- angular 1.5应用程序中的导航栏
- angular的下拉菜单
- Angular只从数组中获取所需的数据
- 如何将不可变的js导入angular 2(alpha)
- Angular js-返回一个包含类似
- 如何使用 Angular JS 将数据保存在数据库中
- 将JSON对象传递给angular指令
- 从HTTPGET返回一个自定义对象列表,以便在Angular 2应用程序中使用
- Angular:更新一次性绑定的数据
- 同步调用,直到用户通过angular验证为访问者
- 将Angular js与taglib结合使用
- 在Angular Fullstack中设置TinyMCE
- Angular Recursion