我正在努力学习开发,如果我有点不了解,请见谅。我试着在这里搜索解决方案。 我必须发表评论并回复应用程序。我正在使用此功能向我的 View 添加评论。
$scope.insertComment = function(){
var new_comment_id = $scope.comments[$scope.comments.length - 1].commentID +1;
var input = {
"commentID" : new_comment_id,
"userID": user.user_id,
"name": user.user_name,
"avatar_url": user.avatar,
"says": $scope.new_comment,
"likes": 0,
"like_status": false,
"replies": []
};
//Pushes changes to the global comment object
$scope.comments.push(input);
$scope.new_comment = '';
}
每个评论都有回复选项,下面的事件显示一个表单以添加对评论的回复。
$(".no-url").click(function(){
console.log('test2');
$(this).parent().children('.reply-form').addClass('active');
});
我的问题是,当我添加新评论时,它没有关联此事件监听器。如何解决?
最佳答案
HTML:
<div comment-click>
//your comment html will goes here.
</div>
JS:
app.directive("commentClick",function(){
return {
link : function(scope,ele,attr){
ele.on('click',function(){
//put here your commnet scropt
})
}
}
})
将此 comment-click
属性添加到您要在其上绑定(bind)点击事件的新添加的 DOME 元素
关于javascript - AngularJS:在 .post() 之后添加事件监听器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37086834/