【发布时间】:2015-10-06 19:21:57
【问题描述】:
我正在尝试用 Angular 编写一个“cmets”指令来加载嵌套的 cmets(来自 Json 数据)并为子 cmets/回复重用相同的指令。
父 cmets 可以自行加载,但是当我尝试在其自己的模板中再次使用 'cmets' 指令显示子 cmets 时,应用程序会冻结,我必须将其关闭。
下面是我的一些代码:
app.html: ---
<ul ng-repeat="comment in View2.postItems | limitTo: 10">
<comments collection="comment"></comments>
</ul>
cmets.html(指令):----
<li>
<span>
{{ collection.data.commentText }}
<ul ng-show="{{collection.data.replies}}"
ng-repeat="comment in collection.data.replies.data.children">
<!-**child comments: this line causes the app to freeze:**-->
<comments collection="comment"></comments>
</ul>
</span>
</li>
cmets.js:---
var comments = function(){
return {
templateUrl : 'modules/comments/comments.html',
restrict:'E',
scope:{
collection: '='
},
link: function(scope, element, attrs){
}
};
};
【问题讨论】:
标签: javascript angularjs web-applications angularjs-directive javascript-framework