我意识到这可能是一个骗局,但毫无疑问,我找到的答案可以解决我的问题。
我有一个功能可以在新闻文章中添加评论。
apt-get
}
这就是我在视图中使用该功能的方法。注释是我用ngRepeat循环的范围变量。
//Post a comment on an event.
$scope.commentEvent = function(event, callback) {
$scope.user = userService.get({id: $rootScope.current_user_id}, function(){
event.newComment.event = event._id;
event.newComment.author = $rootScope.current_user;
event.newComment.author_id = $rootScope.current_user_id;
event.newComment.author_portrait = $scope.user.portrait;
//Save the comment to db
eventCommentService.save(event.newComment, function() {
//Add reference to new comment to the news article.
eventService.update({id: event._id, comments: event.comments.push(event.newComment)}, function() {
event.newComment = null;
//update scope and return it
return $scope.getEventComments(event)
})
});
});
};
//Get all comments related to a specific event.
$scope.getEventComments = function(event) {
return eventCommentService.query({id:event._id});
我的问题是<form ng-Submit="comments = commentEvent(event)">
没有返回更新的范围,因为返回是在嵌套函数中。如何从嵌套回调函数返回值?